PHP code example of amttgroup / yii2-web-uploader

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

    

amttgroup / yii2-web-uploader example snippets



use \kriss\webUploader\widgets\QuickWebUploader;

echo QuickWebUploader::widget([
    'fileNumLimit' => 5,
]);
// or
echo $form->field($model, 'file')->widget(QuickWebUploader::class, [
    'uploadUrl' => ['/file/upload'],
]);



namespace admin\controllers;

use yii\web\Controller;
use kriss\webUploader\actions\QuickDeleteAction;
use kriss\webUploader\actions\QuickUploadAction;

class FileController extends Controller
{
    public function actions()
    {
        return [
            'upload' => [
                'class' => QuickUploadAction::class,
                'savePath' => '@webroot/uploads',
                'displayPath' => '@web/uploads',
            ],
            'delete' => [
                'class' => QuickDeleteAction::class,
                'savePath' => '@webroot/uploads',
                'displayPath' => '@web/uploads',
            ],
        ];
    }
}


// for client validate
// QuickWebUploader
[
    'pluginOptions' => [
        'accept' => [
            'extensions' => 'png,jpeg,jpg,gif',
            'mimeTypes' => 'image/*',
        ],
    ],
];

// for server validate
// QuickUploadAction
[
    'validationRules' => [
        ['file', 'file', 'extensions' => ['png', 'jpeg', 'jpg', 'gif'], 'mimeTypes' => 'image/*', 'maxSize' => 5*1024*1024]
    ],
];