fgh151/yii2-s3-upload
最新稳定版本:0.0.3
Composer 安装命令:
composer require fgh151/yii2-s3-upload
包简介
Yii2 S3 upload extension
关键字:
README 文档
README
S3 upload extension
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist fgh151/yii2-s3-upload "*"
or add
"fgh151/yii2-s3-upload": "*"
to the require section of your composer.json file.
Usage
Add component to config file :
<?= 'components' => [ 'storage' => [ 'class' => fgh151\yii2\s3upload\S3Storage::class, 'key' => 's3-api-key', 'secret' => 's3-api-secret', 'bucket' => 'bucket-name' //You may also change region, provider, etc ], ] ?>
Your form model:
class FormModel extends \yii\db\ActiveRecord { public $uploadImage; public $pathToImage; public function rules() { return [ ['uploadImage', 'file', 'extensions' => ['png', 'jpg', 'jpeg']], ]; } public function behaviors() { return [ [ 'class' => fgh151\yii2\s3upload\S3UploadBehavior::class, //Behavior class 'attribute' => 'uploadImage', 'storageAttribute' => 'pathToImage', //Entity indefier in mapping clas ], ]; } public function afterSave($insert,$changedAttributes){ parent::afterSave($insert,$changedAttributes); if ($this->pathToImage !== null) { //TODO: save $this->pathToImage } } }
Form field example:
<?= $form->field($model, 'uploadImage')->fileInput() ?>
For use with dynamic forms like yii2-dynamicform, you dont need set behaviour in model function. But in controller, when create models, must set:
$images = Model::createMultiple(StoreImage::class, $images); foreach ($images as $i => $image) { $image->attachBehavior('upload', [ 'class' => S3UploadBehavior::class, //Behavior class 'attribute' => "[{$i}]file_upload", // Because input name is different 'storageAttribute' => 'file', //Entity indefier in mapping clas 'path' => 'product', //Entity indefier in mapping clas ]); }
统计信息
- 总下载量: 1.34k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-03-12