Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Multiple file upload

I want to upload to file in the process of a registration. There two file uploads named 'Photo' and 'Signature'. I want to upload the file with custom name in different folders. I search a lot but i can't file code.



9.8k

This is a pretty general question, but basically you will want to create two file fields using Phalcon\Tag, then check for files using Phalcon\Http\Request\File. Also make sure your 'enctype' in your form tag is "multipart/form-data"

In your form:

echo $this->tag->fileField('my_file');
echo $this->tag->fileField('my_file2');

Then in your controller where you $_POST your form to, something like this:

if ($this->request->hasFiles() == true) {
    foreach ($this->request->getUploadedFiles() as $upload) {
            $path = '/my/uploads/dir/' . $upload->getName();
            $upload->moveTo($path);
    }
}


13.9k

Thanks for your quick reply. But I want to move each file on seperate folder and update file name to table.

What you're asking is basically for code to do the whole upload process. That process involves lots of different aspects. Do a Google search for "PHP file upload" to get the basic process down. Then post questions about particular functionality.



13.9k

I want to know Phalcon PHP's way to do this. I can google for Native PHP's way to upload multiple files.



49.5k
Accepted
answer

Phalcon doesn't have any special functionality for moving files around on the server.

Updating a file name in a table is simply done with PHQL or ORM - both of which are mentioned in the docs.



13.9k

Tanks for help from all experts. Finally, I got solution

moveuploadedfile($FILES['signature']['tmpname'], 'files/signature/');