PHP code example of dkhlystov / yii2-uploadimage

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

    

dkhlystov / yii2-uploadimage example snippets


    'modules' => [
        //...
        'uploadimage' => 'dkhlystov\uploadimage\Module',
    ],

<?= \dkhlystov\uploadimage\widgets\UploadImage::widget([
        'model' => $model,
        'attribute' => 'image',
]); 

<?= $form->field($model, 'image')->widget(\dkhlystov\uploadimage\widgets\UploadImage::className()) 

<?= \dkhlystov\uploadimage\widgets\UploadImage::widget([
        'model' => $model,
        'attribute' => 'image',
        'thumbAttribute' => 'thumb',
]); 

<?= \dkhlystov\uploadimage\widgets\UploadImages::widget([
        'model' => $model,
        'attribute' => 'images',
        'fileKey' => 'file',
]); 

<?= $form->field($model, 'image')->widget(\dkhlystov\uploadimage\widgets\UploadImage::className(), [
    'width' => 100,
    'height' => 100,
]) 

<?= $form->field($model, 'image')->widget(\dkhlystov\uploadimage\widgets\UploadImage::className(), [
    'maxImageWidth' => 640,
    'maxImageHeight' => 480,
]) 

<?= $form->field($model, 'image')->widget(\dkhlystov\uploadimage\widgets\UploadImage::className(), [
    'thumbAttribute' => 'thumb',
    'thumbWidth' => 200,
    'thumbHeight' => 150,
]) 

<?= \dkhlystov\uploadimage\widgets\UploadImages::widget([
    'model' => $model,
    'attribute' => 'images',
    'fileKey' => 'file',
    'data' => function($item) {
        return [
            'id' => $item['id'],
            'description' => $item['description'],
        ];
    },
]) 

<?= \dkhlystov\uploadimage\widgets\UploadImages::widget([
    'model' => $model,
    'attribute' => 'images',
    'id' => 'images',
    'fileKey' => 'file',
    'data' => function($item) {
        return ['main' => $item['main']];
    },
    'buttons' => [
        'main' => [
            'label' => '<i class="fa fa-star"></i>',
            'title' => 'Main image',
            'active' => function($item) {
                return $item['main'];
            },
        ],
    ],
])