2017 © Pedro Peláez
 

library yii2-dropzone-widget

yii2-dropzone-widget

image

xj/yii2-dropzone-widget

yii2-dropzone-widget

  • Sunday, May 17, 2015
  • by xjflyttp
  • Repository
  • 3 Watchers
  • 2 Stars
  • 282 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 7 Versions
  • 2 % Grown

The README.md

yii2-dropzone-widget

yii2-dropzone-widget http://www.dropzonejs.com/, (*1)

composer.json

"require": {
    "xj/yii2-dropzone-widget": "*"
},

Action:

public function actions() {
return [
    'upload' => [
        'class' => \xj\dropzone\UploadAction::className(),
        'uploadBasePath' => '@webroot/attachment/album', //file system path
        'uploadBaseUrl' => '@web/attachment/album', //web path
//        'format' => '{yyyy}{mm}{dd}/{time}{rand:6}', // OR Closure
        'format' => function(UploadAction $action) {
            $fileext = $action->uploadFileInstance->getExtension();
            $filehash = sha1(uniqid() . time());
            $p1 = substr($filehash, 0, 2);
            $p2 = substr($filehash, 2, 2);
            return "{$p1}/{$p2}/{$filehash}.{$fileext}";
        },
        'validateOptions' => [
            'extensions' => ['jpg', 'png'],
            'maxSize' => 1 * 1024 * 1024, //file size
        ],
        'beforeValidate' => function($action) {
            $id = Yii::$app->request->get('id');
            if ($id === null) {
                throw new \yii\base\Exception('错误的ID');
            }
            if (Something::findOne($id) === null) {
                throw new \yii\base\Exception('错误的ID');
            }
        },
        'afterValidate' => function($action) {
            //something
        },
        'beforeSave' => function($action) {
            //something
        },
        'afterSave' => function($action) {
            /* @var $action xj\uploadify\UploadAction */
//resize image
            $id = Yii::$app->request->get('id');
            $srcFilename = $action->getUploadFileInstance()->name;
            $image = \xj\kohanaimage\Image::load($action->fullFilename);
            if ($image->width > 1280) {
                $image->resize(1280, NULL)->save();
            }
//insert image to Tables
            $photoModel = Photo::addByImage($action->fullFilename, $action->filename, $id, $srcFilename);
            $action->output['id'] = $photoModel->id;
        },
    ],
];
}

View

Dropzone::widget([
    'url' => ['upload', 'id' => $model->id],
    'id' => 'album-upload',
    'jsOptions' => [
        'previewTemplate' => '<div class="dz-size" data-dz-size></div>',
        'success' => new JsExpression(<<<EOF
function(file, data) {
    console.log(data);
    if (data.error) {
        alert(data.msg);
    } else {
        alert(data.fileUrl);
        alert(data.id);
//etc...
        console.log(file);
    }
}
EOF
),
    ],
    'warpOptions' => ['id' => 'album-upload-dropzone'],
    'formOptions' => ['class' => 'album-upload-dropzone dz-clickable'],
]);

The Versions

17/05 2015

dev-master

9999999-dev

yii2-dropzone-widget

  Sources   Download

BSD-3-Clause

The Requires

 

by Avatar xjflyttp

17/05 2015

1.0.5

1.0.5.0

yii2-dropzone-widget

  Sources   Download

BSD-3-Clause

The Requires

 

by Avatar xjflyttp

18/03 2015

1.0.4

1.0.4.0

yii2-dropzone-widget

  Sources   Download

BSD-3-Clause

The Requires

 

by Avatar xjflyttp

18/03 2015

1.0.3

1.0.3.0

yii2-dropzone-widget

  Sources   Download

BSD-3-Clause

The Requires

 

by Avatar xjflyttp

28/02 2015

1.0.2

1.0.2.0

yii2-dropzone-widget

  Sources   Download

BSD-3-Clause

The Requires

 

by Avatar xjflyttp

24/02 2015

1.0.1

1.0.1.0

yii2-dropzone-widget

  Sources   Download

BSD-3-Clause

The Requires

 

by Avatar xjflyttp

06/02 2015

1.0.0

1.0.0.0

yii2-dropzone-widget

  Sources   Download

BSD-3-Clause

The Requires

 

by Avatar xjflyttp