We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Upload File in API not Working

*<?php $app->post('/uploadAction', function ( ) use ( $app ) {

function uploadAction()
{
    if ($this->request->hasFiles() == true) {
        $baseLocation = 'files/';

        foreach ($this->request->getUploadedFiles() as $file) {
            $photos = new Photo();              
            $photos->name = $file->getName();
            $photos->size = $file->getSize();
            $photos->save();

            $file->moveTo($baseLocation . $file->getName());
        }
    }
}

}); ?>

<form action="uploadAction" method="POST" enctype="multipart/form-data"> <label>File</label> <input type="file" name="upFile"> <input type="submit" name="upload"> </form>*

I want to upload the file to files directory but it's not working. Please help me



79.0k
Accepted
answer
edited Aug '17

And what exactly is not working? You have some error? File missing on a filesystem?

PHP version, PhalconPHP version? SAPI? OS?

You have mentioned API in the title, but you have provided HTML form instead?

When I upload a picture, the image does not go into the files folder. it's result error

You haven't provided any clues nor usable information.

Instead of providing more info for community to help you, you keep opening new threads on this issue, and those should be considered as spam IMO.

the image does not go into the files folder

Then check logs why it does not go into the files folder? There is reason why it doesn't go.