0

I'm working in a form with AngularJS for the front-end and Phalcon PhP for the backend and I'm implementing a upload. I'm using this directive to do so. My problem is that I don't know how handle this upload on a phalcon php action.

Would you have a piece of example code so I could use to start?

Thanks for any help

André Luiz
  • 6,642
  • 9
  • 55
  • 105
  • check the [phalcon documentation for file uploads](https://docs.phalconphp.com/en/latest/api/Phalcon_Http_Request_File.html) – Timothy Aug 24 '16 at 18:40

1 Answers1

1

Something along those lines:

class PostsController extends Controller
{

   public function uploadAction()
   {
      // Check if the user has uploaded files
      if ($this->request->hasFiles() == true) {

        foreach ($this->request->getUploadedFiles() as $file) {
            $path = 'path/to/file' . $file->getName();
            $isUploaded = $file->moveTo($path);
            echo $isUploaded;
        }
    }
   }
}

Of course you have to set routing to point to this controller and function.

boroboris
  • 1,548
  • 1
  • 19
  • 32
  • As posted above getUploadedFiles is working for me too. But the problem was if i wanted to send multipart data - then i needed to use `json_decode($this->request->getPost('somekey'))` – Juri Aug 24 '16 at 18:43
  • sorry I didn't get that. could you post some piece of code you were working on? javascript part also – boroboris Aug 24 '16 at 18:44
  • @boroboris Thanks for your answer! I will be coding then I will set the answer as the correct. – André Luiz Aug 24 '16 at 20:18