PHP code example of i-avatar777 / yii2-widget-file-upload7

1. Go to this page and download the library: Download i-avatar777/yii2-widget-file-upload7 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/ */

    

i-avatar777 / yii2-widget-file-upload7 example snippets


<?= \iAvatar777\widgets\FileUpload7\FileUpload::widget([
    'model'      => $model,
    'attribute'  => 'file',
]) 

<?= $form->field($model, 'user_foto')->widget('\iAvatar777\widgets\FileUpload7\FileUpload',
[
    'update'    => [
        [
            'function' => 'crop',
            'index'    => 'crop',
            'options'  => [
                'width'  => '300',
                'height' => '300',
                'mode'   => 'MODE_THUMBNAIL_CUT',
            ],
        ],
    ],
    'settings' => [
        'maxSize'           => 20 * 1000,
        'server'            => Yii::$app->AvatarCloud->url,
        'controller'        => 'upload',
        'functionSuccess'   => new \yii\web\JsExpression(<<<JS
function (response) {
    // Вызываю AJAX для записи в school_file
    ajaxJson({
        url: '/site/file-upload7-save',
        data: {
            file: response.url,
            school_id: 71,
            type_id: 25,
            size: response.size, // Размер файла в байтах
            update: response.update
        },
        success: function (ret) {
            
        }
    });
}

JS

        ),
    ],
    'events'    => [
        'onDelete' => function ($item) {
            $r = new \cs\services\Url($item['image']);
            $d = pathinfo($r->path);
            $start = $d['dirname'] . '/' . $d['filename'];

            \common\models\school\File::deleteAll(['like', 'file', $start]);
        },
    ],
]
)