2017 © Pedro Peláez
 

yii2-extension yii2-dermadropzone

Yii2 dropzone extension

image

hamada/yii2-dermadropzone

Yii2 dropzone extension

  • Saturday, June 18, 2016
  • by andreyderma
  • Repository
  • 1 Watchers
  • 1 Stars
  • 8 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Yii2 dropzone extension

Yii2 dropzone extension, (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

php composer.phar require --prefer-dist hamada/yii2-dermadropzone "*"

or add, (*4)

"hamada/yii2-dermadropzone": "*"

to the require section of your composer.json file., (*5)

Usage

Once the extension is installed, simply use it in your code by :, (*6)

<?= \Derma\Dropzone\AutoloadExample::widget(); ?> 

More detail options : dropzonejs official docs, (*7)

<?=  \Derma\Dropzone\AutoloadExample::widget([
        'options' => [
            'addRemoveLinks' => true,
            'url'=>Yii::$app->getUrlManager()->createUrl(['tempupload/upload']),
            'acceptedFiles'=> "image/jpeg,image/png",
            'dictDefaultMessage'=>'Pilih gambar atau tarik gambar ke sini. ',
        ],
        'clientEvents' => [
            'success'=> "function(file,response){
                console.log(file);
            }",
            'removedfile' => "function(file){
                console.log(file);
            }"
        ],
    ]);
?>

Add existing images:, (*8)

<?php  
    $arr = []; //store in array
    foreach ($modelImages as $values)
    {
        $arr[] = array(
            'name'=>$values->filename,
            'fileUrl'=>'YOUR_FILE_URL'
        );
        /*
            Example amazon s3 url
            https://s3-ap-southeast-1.amazonaws.com/bucket/donald_trump_sucks.jpg
        */
    }

    echo \Derma\Dropzone\AutoloadExample::widget([
            'addFiles'=>$arr, //put your array here
            'options' => [
                'addRemoveLinks' => true,
                'url'=>Yii::$app->getUrlManager()->createUrl(['tempupload/upload']),
                'acceptedFiles'=> "image/jpeg,image/png",
                'dictDefaultMessage'=>'Pilih gambar atau tarik gambar ke sini. ',
            ],
            'clientEvents' => [
                'success'=> "function(file,response){
                    console.log(file);
                }",
                'removedfile' => "function(file){
                    console.log(file);
                }"
            ],
        ]);
?>

Example of upload method :, (*9)

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

    if (isset($_FILES[$fileName])) {
        $file = \yii\web\UploadedFile::getInstanceByName($fileName);
        if ($file->saveAs($uploadPath . '/' . $file->name)) {
            //Save to database here
            echo \yii\helpers\Json::encode($file);
        }
    }

    return false;
}

The Versions

18/06 2016

dev-master

9999999-dev

Yii2 dropzone extension

  Sources   Download

BSD-3-Clause

The Requires

 

by Andrey derma

extension yii2