This behavior automatically uploads file and fills the specified attribute with a value of the name of the uploaded file.
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist mongosoft/yii2-upload-behavior "*"
or add
"mongosoft/yii2-upload-behavior": "*"
to the require
section of your composer.json.
function behaviors()
{
return [
[
'class' => UploadBehavior::className(),
'attribute' => 'file',
'scenarios' => ['insert', 'update'],
'path' => '@webroot/upload/{id}',
'url' => '@web/upload/{id}',
],
];
}
function behaviors()
{
return [
[
'class' => UploadBehavior::className(),
'attribute' => 'file',
'scenarios' => ['insert', 'update'],
'placeholder' => '@app/modules/user/assets/images/userpic.jpg',
'path' => '@webroot/upload/{id}/images',
'url' => '@web/upload/{id}/images',
],
];
}