oleg-chulakov-studio/yii2-filesaver
Composer 安装命令:
composer require oleg-chulakov-studio/yii2-filesaver
包简介
Yii2 behavior for saving file in model
README 文档
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();
统计信息
- 总下载量: 20
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD
- 更新时间: 2017-07-12