efineuploader EFineUploader: Uploading files using ajax (without flash)

  1. Installation
  2. Requirements
  3. Usage
  4. Resources

Uploading files using ajax (without flash).
Based on https://github.com/Widen/fine-uploader

Installation

  • Extract the release file under protected/extensions/EFineUploader

Requirements

  • Yii 1.1 or above

Usage

view:

<?$this->widget('ext.EFineUploader.EFineUploader',
 array(
       'id'=>'FineUploader',
       'config'=>array(
                       'autoUpload'=>true,
                       'request'=>array(
                          'endpoint'=>'/files/upload',// OR $this->createUrl('files/upload'),
                          'params'=>array('YII_CSRF_TOKEN'=>Yii::app()->request->csrfToken),
                                       ),
                       'retry'=>array('enableAuto'=>true,'preventRetryResponseProperty'=>true),
                       'chunking'=>array('enable'=>true,'partSize'=>100),//bytes
                       'callbacks'=>array(
                                        //'onComplete'=>"js:function(id, name, response){  }",
                                        //'onError'=>"js:function(id, name, errorReason){ }",
                                         ),
                       'validation'=>array(
                                 'allowedExtensions'=>array('jpg','jpeg'),
                                 'sizeLimit'=>2 * 1024 * 1024,//maximum file size in bytes
                                 'minSizeLimit'=>2*1024*1024,// minimum file size in bytes
                                          ),
                      )
      ));

?>

controller:

public function actionUpload()
        {
                $tempFolder=Yii::getPathOfAlias('webroot').'/upload/temp/';

                mkdir($tempFolder, 0777, TRUE);
                mkdir($tempFolder.'chunks', 0777, TRUE);

                Yii::import("ext.EFineUploader.qqFileUploader");

                $uploader = new qqFileUploader();
                $uploader->allowedExtensions = array('jpg','jpeg');
                $uploader->sizeLimit = 2 * 1024 * 1024;//maximum file size in bytes
                $uploader->chunksFolder = $tempFolder.'chunks';

                $result = $uploader->handleUpload($tempFolder);
                $result['filename'] = $uploader->getUploadName();
                $result['folder'] = $webFolder;

                $uploadedFile=$tempFolder.$result['filename'];

                header("Content-Type: text/plain");
                $result=htmlspecialchars(json_encode($result), ENT_NOQUOTES);
                echo $result;
                Yii::app()->end();
        }


Resources

11 3
23 followers
4 551 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: User Interface
Tags: ajax, upload
Developed by: kosenka
Created on: Apr 23, 2013
Last updated: 5 years ago

Downloads

show all

Related Extensions