vinpel/yii2-dropzone

DropzoneJs Extention for Yii2 based on Parminder repo

Installs: 5 026

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 27

Type:yii2-extension

v1.0.5 2017-11-10 12:57 UTC

This package is not auto-updated.

Last update: 2024-11-10 05:19:37 UTC


README

DropzoneJs Extention for Yii2

A port of DropzoneJs for Yii2 Framework

based from work of Parminder Klair : https://github.com/perminder-klair/yii2-dropzone

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist vinpel/yii2-dropzone "~1.0.4"

or add

"vinpel/yii2-dropzone": "~1.0.4"

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 \vinpel\DropZone::widget();

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

echo \vinpel\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;
}