PHPackages                             xingkoo/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. [API Development](/categories/api)
4. /
5. xingkoo/yii2-qiniu-sdk

ActiveYii2-extension[API Development](/categories/api)

xingkoo/yii2-qiniu-sdk
======================

Qiniu API for Yii 2.0

011PHP

Since Apr 17Pushed 7y ago1 watchersCompare

[ Source](https://github.com/xingkoo/yii2-qiniu-sdk)[ Packagist](https://packagist.org/packages/xingkoo/yii2-qiniu-sdk)[ RSS](/packages/xingkoo-yii2-qiniu-sdk/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

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

[](#yii2-qiniu-sdk)

基于Yii2实现的七牛云存储API SDK（使用官方SDK）（目前开发中）

环境条件
----

[](#环境条件)

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

安装
--

[](#安装)

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

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

设置方法
----

[](#设置方法)

```
// 全局使用
// 在config/main.php配置文件中定义component配置信息
'components' => [
  .....
  'qiniu' => [
      'class' => 'xingkoo\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' => 'xingkoo\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
}
```

```
$download = 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

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

Top contributor holds 58.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/050546922ede9247e24cae1f0b1e243c3c3cb18e613edf24d4fc7f85e7439d0a?d=identicon)[xingkoo](/maintainers/xingkoo)

---

Top Contributors

[![xingkoo](https://avatars.githubusercontent.com/u/2936579?v=4)](https://github.com/xingkoo "xingkoo (10 commits)")[![chocoboxxf](https://avatars.githubusercontent.com/u/3401509?v=4)](https://github.com/chocoboxxf "chocoboxxf (7 commits)")

### Embed Badge

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

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

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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