PHPackages                             jerray/qcloud-cos-php-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. [File &amp; Storage](/categories/file-storage)
4. /
5. jerray/qcloud-cos-php-sdk

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

jerray/qcloud-cos-php-sdk
=========================

Tencentyun COS PHP SDK

0.5.0(10y ago)10853MITPHPPHP &gt;=5.5.9

Since Apr 7Pushed 10y ago1 watchersCompare

[ Source](https://github.com/jerray/qcloud-cos-php-sdk)[ Packagist](https://packagist.org/packages/jerray/qcloud-cos-php-sdk)[ Docs](https://github.com/jerray/qcloud-cos-php-sdk)[ RSS](/packages/jerray-qcloud-cos-php-sdk/feed)WikiDiscussions master Synced 1mo ago

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

qcloud-cos-php-sdk
==================

[](#qcloud-cos-php-sdk)

腾讯云[对象存储服务 COS](http://www.qcloud.com/wiki/COS%E4%BA%A7%E5%93%81%E4%BB%8B%E7%BB%8D) PHP SDK

[![Latest Stable Version](https://camo.githubusercontent.com/ce5f7ebac714577b9d5a57f5bc7a443bcd9b96737e3f04c15d4d40cff726826d/68747470733a2f2f706f7365722e707567782e6f72672f6a65727261792f71636c6f75642d636f732d7068702d73646b2f762f737461626c65)](https://packagist.org/packages/jerray/qcloud-cos-php-sdk) [![Total Downloads](https://camo.githubusercontent.com/a86ca0979fb7e4f3fb7f3bda9450315e1e8f6e5d3cfc177f9bdfc81bd3c11a56/68747470733a2f2f706f7365722e707567782e6f72672f6a65727261792f71636c6f75642d636f732d7068702d73646b2f646f776e6c6f616473)](https://packagist.org/packages/jerray/qcloud-cos-php-sdk) [![Latest Unstable Version](https://camo.githubusercontent.com/f8ee0cbf7a5904696caca9083f350d5ad57b1131502fa05c2f189bdf1b6d4279/68747470733a2f2f706f7365722e707567782e6f72672f6a65727261792f71636c6f75642d636f732d7068702d73646b2f762f756e737461626c65)](https://packagist.org/packages/jerray/qcloud-cos-php-sdk) [![License](https://camo.githubusercontent.com/c5d02de9482fc2466d9073ed5adc201dc535b86d259af40aa4dd60dc0701073e/68747470733a2f2f706f7365722e707567782e6f72672f6a65727261792f71636c6f75642d636f732d7068702d73646b2f6c6963656e7365)](https://packagist.org/packages/jerray/qcloud-cos-php-sdk) [![Build Status](https://camo.githubusercontent.com/f5bcd326c37c2354846493196731eaf3d679d11784b4721117321f18ad9feeb3/68747470733a2f2f7472617669732d63692e6f72672f6a65727261792f71636c6f75642d636f732d7068702d73646b2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/jerray/qcloud-cos-php-sdk) [![Coverage Status](https://camo.githubusercontent.com/2cdd7b5164a167e2549917d5e9165da8023065dd258569d48a3ccf7788c3f61c/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6a65727261792f71636c6f75642d636f732d7068702d73646b2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/jerray/qcloud-cos-php-sdk?branch=master)

安装
--

[](#安装)

```
composer require jerray/qcloud-cos-php-sdk

```

使用方法
----

[](#使用方法)

### 创建客户端实例

[](#创建客户端实例)

创建SDK客户端实例。`$options`中的参数请到腾讯云对象存储的[密钥管理](https://console.qcloud.com/cos/project)页面获取。

```
$options = [
    'appId' => 'Your app id',
    'secretId' => 'Your secret id',
    'secretKey' => 'Your secret key',
];
$cos = new jerray\QCloudCos\QCloudCos($options);
```

各接口返回结果详情参见腾讯云对象存储服务 [RESTful API文档](http://www.qcloud.com/wiki/RESTful_API%E6%96%87%E6%A1%A3)

### 文件操作

[](#文件操作)

完整上传

```
$localFilePath = '/path/to/a/local/file';
$bucketName = 'bucket';
$cosFilePath = '/remote/file/path';
$bizAttr = 'File attributes';

try {
    $response = $cos->upload($localFilePath, $bucketName, $cosFilePath, $bizAttr);
    $code = $response->code;
    $fileUrl = $response->data->access_url;
} catch (jerray\QCloudCos\Exceptions\RequestException $e) {
    $response = $e->getBody();
    $httpMessage = $e->getMessage();
    $httpCode = $e->getCode();
} catch (Exception $e) {
    // ...
}
```

分片上传（超过一定大小的文件需要使用分片上传）

```
// response为最后一片的响应，与完整上传结构相同
$response = $cos->uploadSlice($localFilePath, $bucketName, $cosFilePath, $bizAttr);
```

查询文件

```
$response = $cos->queryFile($bucketName, $cosFilePath);
```

更新文件bizAttr

```
$response = $cos->updateFile($bucketName, $cosFilePath, $bizAttr);
```

删除文件

```
$response = $cos->deleteFile($bucketName, $cosFilePath);
```

下载文件

```
$result = $cos->downloadFile($bucketName, $cosFilePath, $localFilePath);

```

### 目录操作

[](#目录操作)

创建目录

```
$response = $cos->createFolder($bucketName, 'test/');
```

目录列表

```
$limit = 20; // 每页列表数量
$pattern = 'both'; // 显示所有文件和目录 file - 只显示文件；foler - 只显示目录

// direction参数需要配合context参数使用
// context为空时始终取第一页，第一页返回的数据中会含有context参数
// 将此context值传入再次调用，即取到第二页
// direction用来控制翻页方向，next下一页，prev前一页
$context = '';
$direction = 'next';

// 取到第一页 返回当前context为第一页
$response = $cos->listFolder($bucketName, 'test/', $limit, $pattern, $context, $direction);

// next 向后翻页，取到第二页，返回当前context为第二页
$response = $cos->listFolder($bucketName, 'test/', $limit, $pattern, $response->data->context, 'next');

// prev 向前翻页，取到第一页，返回当前context为第一页
$response = $cos->listFolder($bucketName, 'test/', $limit, $pattern, $response->data->context, 'prev');
```

更新目录bizAttr

```
$response = $cos->updateFolder($bucketName, 'test/');
```

目录查询

```
$response = $cos->queryFolder($bucketName, 'test/');
```

删除目录

**注意**：目录不为空时会删除失败并抛出 `jerray\QCloudCos\Exceptions\ClientException` 异常

```
$response = $cos->deleteFolder($bucketName, 'test/');
```

### Exceptions

[](#exceptions)

接口请求异常

接口返回4xx错误时，抛出 `jerray\QCloudCos\Exceptions\ClientException`。 返回5xx错误时， 抛出 `jerray\QCloudCos\Exceptions\ServerException`。 这两个异常均继承自 `jerray\QCloudCos\Exceptions\RequestException`。

运行时异常

涉及到本地文件读取的接口，如果本地文件不存在或读取失败，会抛出 `jerray\QCloudCos\Exceptions\FileNotFoundException`。 创建实例时，如果传入的自定义存储（参数`store`，可选参数）没有实现 `jerray\QCloudCos\Contracts\Store` 接口， 抛出 `jerray\QCloudCos\Exceptions\InvalidStoreInstance` 。 这两个异常均继承自 `jerray\QCloudCos\Exceptions\RuntimeException`。

License
-------

[](#license)

MIT

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity52

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

Total

5

Last Release

3672d ago

PHP version history (2 changes)0.1.0PHP &gt;=5.3.0

0.2.0PHP &gt;=5.5.9

### Community

Maintainers

![](https://www.gravatar.com/avatar/544db063a61da70c5ff273c203b1203d3cd5cd4bcdf173b82dcc9eb81b8cb7eb?d=identicon)[jerray](/maintainers/jerray)

---

Top Contributors

[![jerray](https://avatars.githubusercontent.com/u/591094?v=4)](https://github.com/jerray "jerray (11 commits)")

---

Tags

sdktencentyunqcloudcos

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jerray-qcloud-cos-php-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/jerray-qcloud-cos-php-sdk/health.svg)](https://phpackages.com/packages/jerray-qcloud-cos-php-sdk)
```

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k511.3M2.2k](/packages/aws-aws-sdk-php)[qcloud/cos-sdk-v5

PHP SDK for QCloud COS

2051.5M129](/packages/qcloud-cos-sdk-v5)[azure-oss/storage

Azure Blob Storage PHP SDK

37985.0k5](/packages/azure-oss-storage)[tencentyun-api/qcloudapi-sdk-php

php sdk for qcloudapi

10948.9k](/packages/tencentyun-api-qcloudapi-sdk-php)[tencentyun/cos-php-sdk

php sdk for www.qcloud.com cos service

201.4k1](/packages/tencentyun-cos-php-sdk)[codebar-ag/laravel-flysystem-cloudinary

Cloudinary Flysystem v1 integration with Laravel

1224.9k2](/packages/codebar-ag-laravel-flysystem-cloudinary)

PHPackages © 2026

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