PHP code example of oleg-chulakov-studio / yii2-fileinput

1. Go to this page and download the library: Download oleg-chulakov-studio/yii2-fileinput 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/ */

    

oleg-chulakov-studio / yii2-fileinput example snippets


    $form = ActiveForm::begin([
        'options' => ['enctype' => 'multipart/form-data']
    ]); 

    $form = ActiveForm::begin([
        'options' => ['enctype' => 'multipart/form-data']
    ]); 


...
use sem\sortable\actions\DragDropMoveAction;
use Yii;
...
class SliderController extends Controller
{
    ...
    public function actions()
    {
        return [
            ...
            'swap' => [
                'class' => DragDropMoveAction::class,
                'modelClass' => Image::class,
            ],
            ...
        ];
    }
}


...
use Yii;
use sem\sortable\behaviors\SortAttributeBehavior;
...
class Image extends ActiveRecord
{
    ...
    public function rules()
    {
        return [
            ...
            [['sort'], 'number'],
            ...
        ];
    }
    ...
    public function behaviors()
    {
        return [
            ...
            SortAttributeBehavior::class,
            ...
        ];
    }
}

    <?= $form->field($model, 'images[]')->widget(\chulakov\fileinput\widgets\FileInput::className(), [
        'options' => [
            'multiple' => true
        ],
        'sortActionRoute' => ['swap'],
        // !!!!
        'attachedFilesAttribute' => 'imagesAttached',
        // ----
        'pluginOptions' => [
            'overwriteInitial' => false,
            'showUpload' => false,
            'showClose' => false,
            'showRemove' => false,
            'fileActionSettings' => [
                'showRemove' => true,
            ],
        ]
    ]); 

...
class GalleryForm extends \yii\base\Model
{
    ...

    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            ...
            [
                'class' => \chulakov\fileinput\behaviors\FileModelBehavior::class,
            ]
        ];
    }
    ...
}