denchotsanov/yii2-dropzone

Yii2 Dropzone Extension

Installs: 6

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 1

Type:yii2-extension

v1.0.2 2021-04-03 18:29 UTC

This package is auto-updated.

Last update: 2024-10-29 06:30:58 UTC


README

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 denchotsanov/yii2-dropzone "dev-master"

or add

"denchotsanov/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 denchotsanov\DropZone::widget();

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

echo denchotsanov\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);
        if ($file->saveAs($uploadPath . '/' . $file->name)) {
            echo \yii\helpers\Json::encode($file);
        }
    }

    return false;
}