承接 fgh151/yii2-s3-upload 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固