oleg-chulakov-studio / yii2-filesaver
Yii2 behavior for saving file in model
Installs: 19
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 6
Forks: 0
Open Issues: 0
Type:yii2-behaviors
Requires
- php: >=5.4.0
- sem-soft/yii2-filestorage: ^1.0
This package is auto-updated.
Last update: 2024-10-20 01:26:44 UTC
README
Install by composer
composer require oleg-chulakov-studio/yii2-filesaver
Or add this code into require section of your composer.json and then call composer update in console
"oleg-chulakov-studio/yii2-filesaver": "*"
Usage
- In model add behavior
public function behaviors() { return [ .... [ 'class' => FileSaverBehavior::className(), 'group_type' => 'photo', 'in_attribute' => 'photoFile', 'out_attribute' => 'photo_id', 'del_attribute' => 'photoDel', 'allowedExtensions' => [ 'png', 'jpeg', 'jpg' ] ], ... ]; }
- In model add fields
/** * @var UploadedFile /** $photoFile; /** * @var boolean /** $photoDel;
Example usage
- saving by url
$model = new TestModel(); $model->photoFile = new \sem\filestorage\adapters\RemoteFile($url); $model->save();
- saving by upload in form
$model = new TestModel(); $model->photoFile = UploadedFile::getInstance($model, 'photoFile'); $model->save();