PHPackages                             years/yii2-storage - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. years/yii2-storage

ActiveLibrary[File &amp; Storage](/categories/file-storage)

years/yii2-storage
==================

Resource (Cloud) Storage SDK for Yii2

1.0.4(8y ago)136MITPHPPHP &gt;=5.3.3

Since Jul 17Pushed 8y ago1 watchersCompare

[ Source](https://github.com/zxy198717/yii2-storage)[ Packagist](https://packagist.org/packages/years/yii2-storage)[ RSS](/packages/years-yii2-storage/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (5)Dependencies (5)Versions (6)Used By (0)

Yii2 storege - upload behavior for ActiveRecord
===============================================

[](#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.

Based on `Flysystem`, `qiniu` and `oss` supported.

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

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

```

or add

```
"years/yii2-storage": "*"

```

to the `require` section of your composer.json.

Configuration
-------------

[](#configuration)

Add component 'storage'

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

```

Add key `filesystems` to `params.php`

```
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
--------------

[](#uploadbehavior)

This behavior allow you to add file uploading logic with ActiveRecord behavior.

### Usage

[](#usage)

Attach the behavior to your model class:

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

```

Add validation rule:

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

```

Setup proper form enctype:

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

```

File should be uploading fine.

Licence
-------

[](#licence)

MIT

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~15 days

Total

5

Last Release

3207d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/785333?v=4)[Alvin Zeng](/maintainers/zxy198717)[@zxy198717](https://github.com/zxy198717)

---

Top Contributors

[![zxy198717](https://avatars.githubusercontent.com/u/785333?v=4)](https://github.com/zxy198717 "zxy198717 (5 commits)")

---

Tags

sdkcloudstorageyii2qiniuoss

### Embed Badge

![Health badge](/badges/years-yii2-storage/health.svg)

```
[![Health](https://phpackages.com/badges/years-yii2-storage/health.svg)](https://phpackages.com/packages/years-yii2-storage)
```

###  Alternatives

[zgldh/qiniu-laravel-storage

Qiniu Resource (Cloud) Storage SDK for Laravel 5/6/7/8/9

515398.8k14](/packages/zgldh-qiniu-laravel-storage)[qiniu/php-sdk

Qiniu Resource (Cloud) Storage SDK for PHP

8093.0M247](/packages/qiniu-php-sdk)[yangyifan/upload

上传 SDK for Laravel

12122.7k3](/packages/yangyifan-upload)[itbdw/laravel-storage-qiniu

A storage library for laravel5 and qiniu sdk

7015.3k](/packages/itbdw-laravel-storage-qiniu)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
