Symfony Symfony - 1 year ago 112
PHP Question

How to use xupload with Yii

I am new to Yii and want to integrate file uploading.Unfortunately I have not been able to make it work.I have downloaded and extracted the plugin to /extensions/ folder but now I do not know what to do.

Can some one guide me?

here is the link for extension

Ben Ben
Answer Source

that extension is outdated and poorly supported. I use this extension instead: eajaxupload.

As you can see on that page the usage is extremely simple. Upload it to your extensions dir and install it with these few lines of code

First you put the following code in your controller action:

public function actionUpload()

        $folder='upload/';// folder for uploaded files
        $allowedExtensions = array("jpg");//array("jpg","jpeg","gif","exe","mov" and etc...
        $sizeLimit = 10 * 1024 * 1024;// maximum file size in bytes
        $uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
        $result = $uploader->handleUpload($folder);
        $result=htmlspecialchars(json_encode($result), ENT_NOQUOTES);

        $fileSize=filesize($folder.$result['filename']);//GETTING FILE SIZE
        $fileName=$result['filename'];//GETTING FILE NAME

        echo $result;// it's array

After that go to the associated view file for that action and use this code to generate the upload form:

<? $this->widget('ext.EAjaxUpload.EAjaxUpload',
               'allowedExtensions'=>array("jpg");//array("jpg","jpeg","gif","exe","mov" and etc...
               'sizeLimit'=>10*1024*1024,// maximum file size in bytes
               'minSizeLimit'=>10*1024*1024,// minimum file size in bytes
               //'onComplete'=>"js:function(id, fileName, responseJSON){ alert(fileName); }",
               //                  'typeError'=>"{file} has invalid extension. Only {extensions} are allowed.",
               //                  'sizeError'=>"{file} is too large, maximum file size is {sizeLimit}.",
               //                  'minSizeError'=>"{file} is too small, minimum file size is {minSizeLimit}.",
               //                  'emptyError'=>"{file} is empty, please select files again without it.",
               //                  'onLeave'=>"The files are being uploaded, if you leave now the upload will be cancelled."
               //                 ),
               //'showMessage'=>"js:function(message){ alert(message); }"
)); ?>

Extremely easy to get working. Give it a go!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download