nineinchnick/eajaxupload

Yii PHP Framework extension utilizing fileUploader js library to upload files through AJAX without Flash.

This package's canonical repository appears to be gone and the package has been frozen as a result.

Installs: 1 611

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 15

Language:JavaScript

1.0.0 2014-11-04 15:09 UTC

This package is not auto-updated.

Last update: 2021-06-21 11:19:01 UTC


README

This Yii PHP Framework extension allows to upload files using AJAX without Flash.

Installation

Classic

  • Download (zip, tar.gz).
  • Unpack into folder application.extensions.EAjaxUpload. It contents should look like the following:
protected/
├── components/
├── controllers/
├── ... application directories
└── extensions/
    ├── EAjaxUpload/
    │   ├── assets/
    │   └── ... other files of the EAjaxUpload extension
    └── ... other extensions

Composer

  • Run: composer require nineinchnick/EAjaxUpload

Usage

In view/template, use the widget like so:

<? $this->widget('application.vendor.nineinchnick.eajaxupload.EAjaxUpload', array(
    'id'=>'EAjaxUpload',
    'config'=>array(
        'action'=>$this->createUrl('files/uploadByAjax'),
        'template'=>'<div class="qq-uploader"><div class="qq-upload-drop-area"><span>Drop files here to upload</span></div><div class="qq-upload-button">Upload a file</div><ul class="qq-upload-list"></ul></div>',
        'debug'=>false,
        'allowedExtensions'=>array('jpg'),
        '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); }",                                       
        //'messages'=>array(
        //                  '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); }"
    )
)); ?>

Add upload actions to a controller:

    public function actions()
    {
        return array(
            'upload'=>array(
                'class' => 'application.vendor.nineinchnick.eajaxupload.EAjaxUpload',
                'save' => array(
                    'modelClass' => 'EventAttachments',
                    'foreignKey' => 'event_id',
                ),
                'delete' => array(
                    'modelClass' => 'EventAttachments',
                    'foreignKey' => 'event_id',
                ),
            )
        );
    }

Remember to disable CSRF validation for upload actions.

Resources