PHPackages                             yuyangame/yii2-qiniu-sdk - 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. yuyangame/yii2-qiniu-sdk

ActiveYii2-extension

yuyangame/yii2-qiniu-sdk
========================

Qiniu API for Yii 2.0

09PHP

Since Jul 6Pushed 8y ago1 watchersCompare

[ Source](https://github.com/yuyangame/yii2-qiniu-sdk)[ Packagist](https://packagist.org/packages/yuyangame/yii2-qiniu-sdk)[ RSS](/packages/yuyangame-yii2-qiniu-sdk/feed)WikiDiscussions yuyangame Synced 3d ago

READMEChangelogDependenciesVersions (2)Used By (0)

yii2-qiniu-sdk
==============

[](#yii2-qiniu-sdk)

基于Yii2实现的七牛云存储API SDK（使用官方SDK）（目前开发中） 原作者 [@chocoboxxf](https://github.com/chocoboxxf) (我只是添加了自己要用的API，方便自己使用而已)

添加
--

[](#添加)

- download 单文件下载
- more features coming soon

环境条件
----

[](#环境条件)

- > = PHP 5.4
- > = Yii 2.0
- cURL extension

安装
--

[](#安装)

添加下列代码在`composer.json`文件中并执行`composer update --no-dev`操作

```
{
    "require": {
       "yuyangame/yii2-qiniu-sdk": "dev-master"
    }
}
```

设置方法
----

[](#设置方法)

```
// 全局使用
// 在config/main.php配置文件中定义component配置信息
'components' => [
  .....
  'qiniu' => [
      'class' => 'yuyangame\Qiniu\Qiniu',
      'accessKey' => 'Access Key',
      'secretKey' => 'Secret Key',
      'domain' => '七牛域名',
      'bucket' => '空间名',
      'secure' => false, // 是否使用HTTPS，默认为false
  ]
  ....
]
// 代码中调用
$result = Yii::$app->qiniu->putFile('img/test.jpg', __DIR__.'/test.jpg');
....
```

```
// 局部调用
$qiniu = Yii::createObject([
    'class' => 'yuyangame\Qiniu\Qiniu',
    'accessKey' => 'Access Key',
    'secretKey' => 'Secret Key',
    'domain' => '七牛域名',
    'bucket' => '空间名',
    'secure' => false, // 是否使用HTTPS，默认为false
]);
$result = $qiniu->putFile('img/test.jpg', __DIR__.'/test.jpg');
....
```

使用示例
----

[](#使用示例)

上传文件（通过路径）

```
$ret = Yii::$app->qiniu->putFile('img/test.jpg', __DIR__.'/test.jpg');
if ($ret['code'] === 0) {
    // 上传成功
    $url = $ret['result']['url']; // 目标文件的URL地址，如：http://[七牛域名]/img/test.jpg
} else {
    // 上传失败
    $code = $ret['code']; // 错误码
    $message = $ret['message']; // 错误信息
}
```

上传文件（通过内容）

```
$fileData = file_get_contents(__DIR__.'/test.jpg');
$ret = Yii::$app->qiniu->put('img/test.jpg', $fileData);
if ($ret['code'] === 0) {
    // 上传成功
    $url = $ret['result']['url']; // 目标文件的URL地址，如：http://[七牛域名]/img/test.jpg
} else {
    // 上传失败
    $code = $ret['code']; // 错误码
    $message = $ret['message']; // 错误信息
}
```

获取私有文件下载链接

```
$fileList = [
    'http://domain/private-file1.jpg',
    'http://domain/private-file2.jpg',
    'http://domain/private-file3.jpg',
];
$urlMaps = Yii::$app->qiniu->batchDownload($fileList);
foreach ($urlMaps as $fileUrl => $downloadUrl) {
    // TODO
}

// or
$fileName = 'http://domain/private-file1.jpg';
$url = Yii::$app->qiniu->download($fileName);
```

获取上传凭证

```
$bucket = 'test_bucket';
$key = null;
$expires = 7200;
$policy = null;
$token = Yii::$app->qiniu->uploadToken($bucket, $key, $expires, $policy);
// TODO
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 77.8% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/7682cc948241b86df41cf5d1881042708bec5cbb8b86858a4444d9f3bb7e81a4?d=identicon)[yuyangame](/maintainers/yuyangame)

---

Top Contributors

[![chocoboxxf](https://avatars.githubusercontent.com/u/3401509?v=4)](https://github.com/chocoboxxf "chocoboxxf (7 commits)")[![yuyangame](https://avatars.githubusercontent.com/u/7377756?v=4)](https://github.com/yuyangame "yuyangame (2 commits)")

### Embed Badge

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

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

PHPackages © 2026

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