2017 © Pedro Peláez
 

library yii2-storage

Resource (Cloud) Storage SDK for Yii2

image

years/yii2-storage

Resource (Cloud) Storage SDK for Yii2

  • Sunday, September 17, 2017
  • by zxy198717
  • Repository
  • 1 Watchers
  • 0 Stars
  • 21 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 5 % Grown

The README.md

Yii2 storege - upload behavior for ActiveRecord

This package is one ActiveRecord behavior. It allows you to keep the uploaded file as-is. It support multiple attributes and files., (*1)

Based on Flysystem, qiniu and oss supported., (*2)

Installation

The preferred way to install this extension is through composer., (*3)

Either run, (*4)

php composer.phar require --prefer-dist years/yii2-storage "*"

or add, (*5)

"years/yii2-storage": "*"

to the require section of your composer.json., (*6)

Configuration

Add component 'storage', (*7)

'components' => [
        'storage' => [
            'class' => 'years\storage\Storage',
        ],
   ]

Add key filesystems to params.php, (*8)

return [
     xxxxx
    'filesystems' => [
        'default' => 'qiniu',
        'disks' => [
            'local' => [
                'driver' => 'local',
                'root' => '@webroot/upload',
            ],

            's3' => [
                'driver' => 's3',
                'key' => 'your-key',
                'secret' => 'your-secret',
                'region' => 'your-region',
                'bucket' => 'your-bucket',
            ],

            'qiniu' => [
                'driver'  => 'qiniu',
                'domains' => [
                    'default'   => 'olys54us5.bkt.clouddn.com', //你的七牛域名
                    'https'     => '',         //你的HTTPS域名
                    'custom'    => '',                //你的自定义域名
                ],
                'access_key'=> 'xxxxx-BCT2',  //AccessKey
                'secret_key'=> 'xxxx',  //SecretKey
                'bucket'    => 'xxx',  //Bucket名字
                'notify_url'=> '',  //持久化处理回调地址
            ],

            'oss' => [
                'driver'        => 'oss',
                'access_id'     => 'xxxx',
                'access_key'    => 'xxx',
                'bucket'        => 'xxx',
                'endpoint'      => 'oss-cn-hangzhou-internal.aliyuncs.com',
                'isCName'       => false,
                'debug'         => true
            ],
        ],
    ],
];


UploadBehavior

This behavior allow you to add file uploading logic with ActiveRecord behavior., (*9)

Usage

Attach the behavior to your model class:, (*10)

public function behaviors()
{
    return [
        [
            'class' => '\years\storage\behaviors\UploadBehavior',
            'attributes' => 'avatar',
            'disk' => 'qiniu',
            'directory' => 'images',
        ],
    ];
}

Add validation rule:, (*11)

public function rules()
{
    return [
        ['avatar', 'file'],   
    ];
}

Setup proper form enctype:, (*12)

$form = \yii\bootstrap\ActiveForm::begin([
    'enableClientValidation' => false,
    'options' => [
        'enctype' => 'multipart/form-data',
    ],
]);

File should be uploading fine., (*13)

Licence

MIT, (*14)

The Versions

17/09 2017

dev-master

9999999-dev

Resource (Cloud) Storage SDK for Yii2

  Sources   Download

MIT

The Requires

 

by years

yii2 cloud sdk storage qiniu oss

17/09 2017

1.0.4

1.0.4.0

Resource (Cloud) Storage SDK for Yii2

  Sources   Download

MIT

The Requires

 

by years

yii2 cloud sdk storage qiniu oss

03/09 2017

1.0.3

1.0.3.0

Resource (Cloud) Storage SDK for Yii2

  Sources   Download

MIT

The Requires

 

by years

yii2 cloud sdk storage qiniu oss

10/08 2017

1.0.2

1.0.2.0

Resource (Cloud) Storage SDK for Yii2

  Sources   Download

MIT

The Requires

 

by years

yii2 cloud sdk storage qiniu oss

20/07 2017

v1.0.1

1.0.1.0

Resource (Cloud) Storage SDK for Yii2

  Sources   Download

MIT

The Requires

 

by years

yii2 cloud sdk storage qiniu oss

17/07 2017

v1.0.0

1.0.0.0

Resource (Cloud) Storage SDK for Yii2

  Sources   Download

MIT

The Requires

 

by years

yii2 cloud sdk storage qiniu oss