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

How to use blueimp file upload with phalcon?

Hello I want to use https://github.com/blueimp/jQuery-File-Upload plugin with phalcon.Is it possible?How?



85.5k
Accepted
answer
edited Oct '16

the 2 libraries has nothing in common but never the less .


$("#myfield").fileupload({
                acceptFileTypes: /(\.|\/)(jpe?g|png)$/i,
                // The maximum allowed file size in bytes:
                maxFileSize: 10000000, // 10 MB
                // The minimum allowed file size in bytes:
                minFileSize: undefined, // No minimal file size
                maxNumberOfFiles: 10,
                dataType: 'json',
                url: /my controller action url,
                autoUpload: true
            }).on('fileuploadadd', function (e, data) {
            //fired before uploading begins or something like that, you can check the docs really...
            }).on('fileuploadprogressall', function (e, data) {

            //here i use it to show my progress bar
            }).on('fileuploaddone', function (e, data) {
                //caled when upload iis done , console.log(arguments)
            })

for backend i use this helper library.

https://github.com/stanislav-web/phalcon-uploader There are some explanations there, here is my code just in case


$this->uploader->setRules([
            'directory' =>  $this->mainDir,
            'minsize'   =>  1000,
            'maxsize'   =>  10000000,// 10 MB
            'mimes'     =>  [
                'image/jpeg',
                'image/png',
            ],
            'extensions'     =>  [
                'jpeg',
                'jpg',
                'png',
            ],
            'sanitize' => true,
            'hash'     => 'md5'
        ]);

        //////
        if($this->uploader->isValid() === true) {

            $this->uploader->move();

            $info = $this->uploader->getInfo()[0];

            $this->file = $info['path'];
            $this->fileName = $info['filename'];
        }

and thats pretty much it