andrewljashenko / yii2-upload-files-behavior
Upload files via Behavior
Installs: 15
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- gregwar/image: 2.*
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2024-11-13 19:36:58 UTC
README
Upload files via Behavior
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist andrewljashenko/yii2-upload-files-behavior "*"
or add
"andrewljashenko/yii2-upload-files-behavior": "*"
to the require section of your composer.json
file.
Usage
Once the extension is installed, simply use it in your code by :
[ 'class' => UploadFilesBehavior::className(), //Behavior class 'attributes' => [ [ 'attribute' => 'images', 'uploadPath' => '@common/images', 'sizes' => [[100, 100], [200, 250]] ], [ 'attribute' => 'file', 'uploadPath' => '@common/files', ], ] ]
Don't forget enable enctype into ActiveForm
<?php $form = ActiveForm::begin(['options' => ['enctype'=>'multipart/form-data']]); ?> <?= $form->field($model, 'images[]')->fileInput(['multiple' => true]) ?> <?= $form->field($model, 'file')->fileInput() ?> <?php ActiveForm::end(); ?>