Skip to content
DropzoneJs Extention for Yii2
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
assets updated dropzone Nov 9, 2015
bower_components/dropzone updated dropzone Nov 9, 2015
.bowerrc updated to dropzone v3.10.2 Oct 22, 2014
.gitignore updated to dropzone v3.10.2 Oct 22, 2014
DropZone.php Support for enabled csfr validation. Nov 20, 2014
README.md Changed example in README.md Oct 23, 2014
bower.json updated dropzone Nov 9, 2015
composer.json package update Nov 9, 2015

README.md

Yii2 Dropzone

DropzoneJs Extention for Yii2

A port of DropzoneJs for Yii2 Framework

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist perminder-klair/yii2-dropzone "dev-master"

or add

"perminder-klair/yii2-dropzone": "dev-master"

to the require section of your composer.json file.

Usage

Once the extension is installed, simply use it in your code by to create Ajax upload area :

echo \kato\DropZone::widget();

To pass options : (More details at dropzonejs official docs )

echo \kato\DropZone::widget([
       'options' => [
           'maxFilesize' => '2',
       ],
       'clientEvents' => [
           'complete' => "function(file){console.log(file)}",
           'removedfile' => "function(file){alert(file.name + ' is removed')}"
       ],
   ]);

Example of upload method :

public function actionUpload()
{
    $fileName = 'file';
    $uploadPath = './files';

    if (isset($_FILES[$fileName])) {
        $file = \yii\web\UploadedFile::getInstanceByName($fileName);

        //Print file data
        //print_r($file);

        if ($file->saveAs($uploadPath . '/' . $file->name)) {
            //Now save file data to database

            echo \yii\helpers\Json::encode($file);
        }
    }

    return false;
}
You can’t perform that action at this time.