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

Multi file upload


I was looking into implementing 2 different versions of file uploading in my application. The first being single file upload(thumbnails, archive files, etc), and the second being multi for things such as screenshots, galleries, etc.

I know this can be done with ajax, but my question is a simplistic approach(particuarly) a simplistic approach in phalcon to allow both single and multi file uploading without un-necessary overhead and have support for a progression bar.

Any help would be appreciated!


$_FILES is always an array, it is just a way of how you gonna implement it i think ?

also your input should have <input type=file mulitple> in order to be multi upload i think.

So If you have single upload just use first file

edited Jul '18

Basically for a simple solution what you want is a file field like Izo mentions. If you are using form objects its fairly simple to add attributes to the HTML output.

A progress bar is more for clientside scripting and should be possible to implement on anything.

use Phalcon\Forms\Element\File;

$file = new File(
                "placeholder" => "",
                "multiple" => "mulitple"

# will generate 
<input type="file" id="image" name="image" placeholder="" multiple="mulitple">

If you are looking to just generate is via volt you could just write the above HTML output.

If the field does not exist you can create it, I'm using the below to create a input[type="time"] field.

Structure: app/forms/elements/Time.php

namespace PhalconTime\Forms\Elements;

use Phalcon\Forms\Element;
use Phalcon\Forms\ElementInterface;

 * PhalconTime\Forms\Elements\Time
 * Component INPUT[type=time] for forms
class Time extends Element implements ElementInterface

     * Renders the element widget returning html
     * @param array $attributes
     * @return string
    public function render($attributes = null)
        return \Phalcon\Tag::TimeField($this->prepareAttributes($attributes));