承接 mamadali/yii2-s3-storage 相关项目开发

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

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

mamadali/yii2-s3-storage

最新稳定版本:1.0.1

Composer 安装命令:

composer require mamadali/yii2-s3-storage

包简介

A package for yii2 to store files on s3 storage

README 文档

README

Yii2 S3 Storage is a Yii2 component that provides an easy way to store files on Amazon S3.

Latest Stable Version Total Downloads

Installation

The preferred way to install this extension is through composer.

Either run

composer require mamadali/yii2-s3-storage

or add

"mamadali/yii2-s3-storage": "*"

to the require section of your composer.json file. and run composer update

then run migrations

php yii migrate/up --migrationPath=@vendor/mamadali/yii2-s3-storage/src/migrations

Basic usage

add s3 component to components section of config file

    'components' => [
        ...
        's3storage' => [
            'class' => 'mamadali\S3Storage\components\S3Storage',
            'key' => // your access key
            'secret' => // your secret key
            'endpoint' => // your endpoint
            'default_bucket_name' => // your bucket name
            'bucket_domain' => // Optional: your bucket domain
        ],
        ...
    ];

add behavior to your model

    public function behaviors()
    {
        return [
            ...
            [
                'class' => StorageUploadBehavior::class,
                'attributes' => ['file'],
                'scenarios' => [self::SCENARIO_UPLOAD],
                'path' => 'path/model_class/{id}'
            ],
            ...
        ];
    }

then just add file input to your form and save model in controller

    <?= $form->field($model, 'file')->fileInput() ?>
    $model->save();

get usage of storage

S3Storage::formatUsageSpace(Yii::$app->s3storage->getTotalUsage());
// return "1 MB"
S3Storage::formatUsageSpace(Yii::$app->s3storage->getUsageByModelClass(Model::class));
Yii::$app->s3storage->getUsageSeperatedByModelClass();
/**
* return [
 *     [
 *          'model_class' => 'common\models\Model',
 *          'size' => 1048576 // bytes
 *     ],
 * ]
 */

统计信息

  • 总下载量: 27
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-08