PHPackages                             dcb9/yii2-qiniu - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. dcb9/yii2-qiniu

AbandonedArchivedYii2-extension[Utility &amp; Helpers](/categories/utility)

dcb9/yii2-qiniu
===============

The Qiniu integration for the Yii framework

v0.5(9y ago)171.6k10[1 issues](https://github.com/dcb9/yii2-qiniu/issues)1BSD-3-ClausePHPPHP &gt;=5.4.0

Since Jun 1Pushed 9y ago1 watchersCompare

[ Source](https://github.com/dcb9/yii2-qiniu)[ Packagist](https://packagist.org/packages/dcb9/yii2-qiniu)[ RSS](/packages/dcb9-yii2-qiniu/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (5)Dependencies (4)Versions (10)Used By (1)

Qiniu Extension for Yii2
========================

[](#qiniu-extension-for-yii2)

The Qiniu integration for the Yii framework

[![Build Status](https://camo.githubusercontent.com/1dc760a11d82181dbf4e3543a5ddf112e9438b5e8b9ce6fee1e9bdfeb637b86c/68747470733a2f2f7472617669732d63692e6f72672f646362392f796969322d71696e69752e737667)](https://travis-ci.org/dcb9/yii2-qiniu)[![Code Climate](https://camo.githubusercontent.com/09007b0a009a71cd3fa5e8be953939ff12204af388bdd719c8f0222b38cbe07b/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f646362392f796969322d71696e69752f6261646765732f6770612e737667)](https://codeclimate.com/github/dcb9/yii2-qiniu)[![Issue Count](https://camo.githubusercontent.com/69249562f4feef454d05a6532dcc929f6798e7a56d3a807183882d9cbec29df3/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f646362392f796969322d71696e69752f6261646765732f69737375655f636f756e742e737667)](https://codeclimate.com/github/dcb9/yii2-qiniu)[![Latest Stable Version](https://camo.githubusercontent.com/7da437b478313c32510c123009bd2425ce79bd8013a15318da7f4f904b27ce0d/68747470733a2f2f706f7365722e707567782e6f72672f646362392f796969322d71696e69752f76657273696f6e)](https://packagist.org/packages/dcb9/yii2-qiniu)[![Total Downloads](https://camo.githubusercontent.com/59889d32e5023780b536970d7be82198fb9542e48b80badffb91415976bf63bb/68747470733a2f2f706f7365722e707567782e6f72672f646362392f796969322d71696e69752f646f776e6c6f616473)](https://packagist.org/packages/dcb9/yii2-qiniu)[![License](https://camo.githubusercontent.com/2ce7a25abdb060a5aa206e62ef4c9506f47d59b11c1e3f1ed2b9c50d39205cf1/68747470733a2f2f706f7365722e707567782e6f72672f646362392f796969322d71696e69752f6c6963656e7365)](https://packagist.org/packages/dcb9/yii2-qiniu)

[CHANGE LOG](CHANGELOG.md)

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

[](#installation)

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

Either run

```
composer require --prefer-dist dcb9/yii2-qiniu

```

or add

```
"dcb9/yii2-qiniu": "*"
```

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

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

[](#configuration)

To use this extension, simply add the following code in your application configuration:

```
return [
    //....
    'components' => [
        'qiniu' => [
            'class' => 'dcb9\qiniu\Component',
            'accessKey' => 'YOUR_ACCESS_KEY',
            'secretKey' => 'YOUR_SECRET_KEY',
            'disks' => [
                'testBucket' => [
                    'bucket' => 'bucketOnQiniu',
                    'baseUrl' => 'ACCESS_QINIU_URL',
                    'isPrivate' => true,
                    'zone' => 'zone0', // 可设置为 zone0, zone1 @see \Qiniu\Zone
                ],
            ],
        ],
    ],
];
```

[资源操作](http://developer.qiniu.com/code/v6/api/kodo-api/index.html#%E8%B5%84%E6%BA%90%E6%93%8D%E4%BD%9C)
-------------------------------------------------------------------------------------------------------

[](#资源操作)

资源操作就 [Flysystem](https://github.com/thephpleague/flysystem) 的一个扩展, 所以所有的调用方法与 [Flysystem](https://github.com/thephpleague/flysystem) 调用方法一致.

```
// 获取 Disk
$filesystem = Yii::$app->qiniu->getDisk('testBucket');

$filesystem->has('hello.txt');

// 七牛独有 API
$filesystem->getUrl('hello.txt');  // 获取访问地址
```

**[其它所有可调用的 API](http://flysystem.thephpleague.com/api/)**

#### [上传策略](http://developer.qiniu.com/article/developer/security/put-policy.html)

[](#上传策略)

默认设置 Policy 是使用 Array 的方式来设置的, 但是这种方式对程序员不是很友好,于是创建了一个 Policy 的类,但所有的操作还是跟操作数组一样.

```
$policy = new \dcb9\qiniu\Policy();
$policy->callbackUrl = '';
$policy->callbackBody = '';
```

#### [获取 UploadToken](http://developer.qiniu.com/article/developer/security/upload-token.html)

[](#获取-uploadtoken)

```
$qiniu = Yii::$app->qiniu;

$diskName = 'testBucket';
$token1 = $qiniu->getUploadToken($diskName);

$key = null;
$expires = 3600;
$policy = new \dcb9\qiniu\Policy();
$policy->callbackUrl = '';
$policy->callbackBody = '';

// Fop @see src/Pfop.php
$policy->persistentOps = \dcb9\qiniu\Pfop::instance()
    ->avthumb('mp4')
    ->wmImage('http://o82pobmde.bkt.clouddn.com/yii2-logo.png')
    ->saveas('testbucket', 'after-ops' . date('Y-m-d H:i:s') . '.mp4')
    ->__toString();
$policy->persistentNotifyUrl = 'http://blog.phpor.me';

$diskName = 'testBucket';
$token2 = $qiniu->getUploadToken($diskName, $key, $expires, $policy);
```

#### 使用 Token 上传文件

[](#使用-token-上传文件)

```
$token = ''; // @see 获取 UploadToken
$config = ['token' => $token];
$filesystem->writeStream($path, $stream, $config);

$filesystem->write($path, $content, $config);

$filesystem->put($path, $content, $config);
```

Tricks
------

[](#tricks)

- 给配置的组件加 IDE 自动补全 [IDE autocompletion for custom components](https://github.com/samdark/yii2-cookbook/blob/master/book/ide-autocompletion.md)

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 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 ~22 days

Recently: every ~33 days

Total

7

Last Release

3546d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0bf3d81236f12ab8f3274e3e899048d44ed9f85b9537c474d958e7676769f3b8?d=identicon)[bobchengbin](/maintainers/bobchengbin)

---

Top Contributors

[![dcb9](https://avatars.githubusercontent.com/u/3984347?v=4)](https://github.com/dcb9 "dcb9 (16 commits)")

---

Tags

helperyii2qiniudcb9

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dcb9-yii2-qiniu/health.svg)

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

PHPackages © 2026

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