PHP code example of coldfox / yii2-dropzone

1. Go to this page and download the library: Download coldfox/yii2-dropzone library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

coldfox / yii2-dropzone example snippets


    
    public function actions(){
            return [
                'upload' => [
                    'class' => 'coldfox\dropzone\DropZoneUploadAction',
                    'config' => [
                        "filePathFormat" => "/uploads/source_code/".date('Ymd').'/', //上传保存路径
                        "fileRoot" => Yii::getAlias("@uploadRoot"),//上传根目录
                    ],
                ],
                'remove' => [
                    'class' => 'coldfox\dropzone\RemoveAction',
                    'config' => [
                        "fileRoot" => Yii::getAlias("@uploadRoot"),//上传根目录
                    ],
                ],
            ];
        }
   
   

    
    echo \coldfox\dropzone\DropZone::widget();
    //Or
    echo \coldfox\dropzone\DropZone::widget(
        [
            //开启拖拽排序        
            'sortable'=>true,
            /**
             * Sortable配置参数
             * 详情参阅 https://github.com/RubaXa/Sortable#options
             * @var array
             */
            'sortableOption' => [],
            //回显的数据 内容我格式大概就这样子
            'mockFiles'=>['/uploads/image/20180107152242/xxxxxx.jpg','/uploads/image/20180107152242/xxxxxxx.jpg'],
            /*
            * dropzone配置选项,
            * 详情参阅 http://www.dropzonejs.com/#configuration-options
            * @var array
            */
            'clientOptions' => [
                'maxFiles'=>5,
                'maxFilesize' => '7',
                'autoProcessQueue'=>false,
                'dictCancelUpload'=>'取消上传',
                'dictRemoveFile'=>'删除文件',
                'addRemoveLinks'=>true
            ],
           /**dropzone事件侦听
            * 详情参阅 http://www.dropzonejs.com/#event-list
            * @var array
            */
            'clientEvents'=>[
                'success'=>'function (file, response) {console.log(response)}',
            ]
        ]
    );

    //Or
    echo $form->field($model, 'file')->widget('coldfox\dropzone\DropZone', [
        'sortable'=>true,
        'clientOptions' => [
            'maxFilesize' => '7',
            'autoProcessQueue'=>true,
            'dictCancelUpload'=>'取消上传',
            'dictRemoveFile'=>'删除文件',
            'addRemoveLinks'=>true
        ]
    ]);

    
    //Or
    echo \coldfox\dropzone\DropZone::widget([
        'sortable'=>true,
        'model' => $model,
        'attribute' => 'file',
        'clientOptions' => [
            'maxFilesize' => '7',
            'autoProcessQueue'=>true,
            'dictCancelUpload'=>'取消上传',
            'dictRemoveFile'=>'删除文件',
            'addRemoveLinks'=>true
        ]
    ]);
    

php composer.phar