PHP code example of moxuandi / yii2-webuploader

1. Go to this page and download the library: Download moxuandi/yii2-webuploader 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/ */

    

moxuandi / yii2-webuploader example snippets


public function actions()
{
    return [
        'WebUpload' => [
            'class' => 'moxuandi\webuploader\UploaderAction',
            // 可选参数, 参考 UploaderAction::$_config
            'config' => [
                'allowFiles' => ['.png', '.jpg', '.jpeg', '.gif', '.bmp'],  // 上传图片格式显示
                'pathFormat' => '/uploads/image/{yyyy}{mm}{dd}/{hh}{ii}{ss}_{rand:6}',  // 上传保存路径, 可以自定义保存路径和文件名格式

                // 如果`uploads`目录与当前应用的入口文件不在同一个目录, 必须做如下配置:
                'rootPath' => dirname(dirname(Yii::$app->request->scriptFile)),
                'rootUrl' => 'http://image.advanced.ccc',
            ],
        ],
    ];
}

1. 简单调用:
$form->field($model, 'images')->widget('moxuandi\webuploader\MultiImage');

2. 带参数调用:
$form->field($model, 'images')->widget('moxuandi\webuploader\MultiImage', [
    'config'=>[
        'fileNumLimit' => 2,
        'fileSizeLimit' => 30*1024*1024,
        'fileSingleSizeLimit' => 2*1024*1024
    ]
]);

3. 不带 $model 调用:
\moxuandi\webuploader\MultiImage::widget([
    'name' => 'images',
    'value' => $model->images,
    'config'=>[
        'fileNumLimit' => 2,
        'fileSizeLimit' => 30*1024*1024,
        'fileSingleSizeLimit' => 2*1024*1024
    ]
]);