PHPackages                             qcloud/cos-sdk-v5 - 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. qcloud/cos-sdk-v5

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

qcloud/cos-sdk-v5
=================

PHP SDK for QCloud COS

v2.6.16(1y ago)2051.5M—3.5%82[2 issues](https://github.com/tencentyun/cos-php-sdk-v5/issues)[1 PRs](https://github.com/tencentyun/cos-php-sdk-v5/pulls)20MITPHPPHP &gt;=5.6

Since Sep 1Pushed 1mo ago52 watchersCompare

[ Source](https://github.com/tencentyun/cos-php-sdk-v5)[ Packagist](https://packagist.org/packages/qcloud/cos-sdk-v5)[ RSS](/packages/qcloud-cos-sdk-v5/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (3)Versions (77)Used By (20)

COS-PHP-SDK-V5
==============

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

腾讯云 COS-PHP-SDK-V5（[XML API](https://cloud.tencent.com/document/product/436/7751)）

[![PHP Version](https://camo.githubusercontent.com/b0e5a3029741522faf08313e373725cd8b2d6d1c01ab7c2c4fb700521cd940cd/687474703a2f2f706f7365722e707567782e6f72672f71636c6f75642f636f732d73646b2d76352f726571756972652f706870)](https://packagist.org/packages/qcloud/cos-sdk-v5)[![License](https://camo.githubusercontent.com/fb271056a77b58f67ce76415e965c5ccb2585160dd656e627271a7a02a26b754/68747470733a2f2f706f7365722e707567782e6f72672f71636c6f75642f636f732d73646b2d76352f6c6963656e7365)](LICENSE)[![Latest Stable Version](https://camo.githubusercontent.com/9adf1ddf4228709ce56dfe99754e2092b488850e279d793c4c0e38a66191c8fc/68747470733a2f2f706f7365722e707567782e6f72672f71636c6f75642f636f732d73646b2d76352f762f737461626c65)](https://packagist.org/packages/qcloud/cos-sdk-v5)[![Total Downloads](https://camo.githubusercontent.com/a3bc339f6888d2229a3fd4b0653d00c9abba17bbacb1b9849588ebf6018d6b15/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f71636c6f75642f636f732d73646b2d76352e7376673f7374796c653d666c6174)](https://packagist.org/packages/qcloud/cos-sdk-v5)[![Build Status](https://camo.githubusercontent.com/086a20b94a59369a083549856c901a98e3587ce3f3c691067748665d173f5655/68747470733a2f2f6170692e7472617669732d63692e636f6d2f74656e63656e7479756e2f636f732d7068702d73646b2d76352e7376673f6272616e63683d6d6173746572)](https://app.travis-ci.com/github/tencentyun/cos-php-sdk-v5)[![codecov](https://camo.githubusercontent.com/a233646c1001767d98fb66b96c71f52c47d8f3dcfd8aa163b294e027ee88524a/68747470733a2f2f636f6465636f762e696f2f67682f74656e63656e7479756e2f636f732d7068702d73646b2d76352f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/tencentyun/cos-php-sdk-v5)[![Support Multiple Versions](https://github.com/tencentyun/cos-php-sdk-v5/actions/workflows/install.yml/badge.svg)](https://github.com/tencentyun/cos-php-sdk-v5/actions/workflows/install.yml)

依赖
--

[](#依赖)

- PHP &gt;= 5.6

> 如果您的 php 版本 `>=5.3` 且 ` 您可以在 [Composer 官网](https://getcomposer.org/) 上找到更多关于如何安装 Composer，配置自动加载以及用于定义依赖项的其他最佳实践等相关信息。

#### 安装步骤

[](#安装步骤)

1. 打开终端；
2. 下载 Composer，执行以下命令：

```
curl -sS https://getcomposer.org/installer | php
```

3. 创建一个名为`composer.json`的文件，内容如下：

```
{
    "require": {
        "qcloud/cos-sdk-v5": "2.*"
    }
}
```

4. 使用 Composer 安装，执行以下命令：

```
php composer.phar install
```

使用该命令后会在当前目录中创建一个 vendor 文件夹，里面包含 SDK 的依赖库和一个 autoload.php 脚本，方便在项目中调用。

5. 通过 autoload.php 脚本调用 cos-php-sdk-v5：

```
require '/path/to/vendor/autoload.php';
```

现在您的项目已经可以使用 COS 的 V5 版本 SDK 了。

### Phar 方式

[](#phar-方式)

Phar 方式安装 SDK 的步骤如下：

1. 在 [GitHub 发布页面](https://github.com/tencentyun/cos-php-sdk-v5/releases) 下载相应的 phar 文件；

> 对于 PHP 版本`>= 5.6`且` 对于 PHP 版本`>=7.2.5`的用户请下载`cos-sdk-v5-7.phar`以使用 Guzzle7 版本。

2. 在代码中引入 phar 文件：

```
require '/path/to/cos-sdk-v5.phar';
```

### 源码方式

[](#源码方式)

源码方式安装 SDK 的步骤如下：

1. 在 [GitHub 发布页面](https://github.com/tencentyun/cos-php-sdk-v5/releases) 下载相应的 cos-sdk-v5.tar.gz 文件；

> 对于 PHP 版本`>= 5.6`且` 对于 PHP 版本`>=7.2.5`的用户请下载`cos-sdk-v5-7.tar.gz`以使用 Guzzle7 版本。

2. 解压后通过 autoload.php 脚本加载 SDK：

```
require '/path/to/cos-sdk-v5/vendor/autoload.php';
```

快速入门
----

[](#快速入门)

可参照 Demo 程序，详见 [sample 目录](https://github.com/tencentyun/cos-php-sdk-v5/tree/master/sample) 。

接口文档
----

[](#接口文档)

PHP SDK 接口文档，详见

### 配置文件

[](#配置文件)

```
$cosClient = new Qcloud\Cos\Client(array(
    'region' => '',
    'credentials' => array(
        'secretId' => '',
        'secretKey' => ''
    )
));
```

若您使用 [临时密钥](https://cloud.tencent.com/document/product/436/14048) 初始化，请用下面方式创建实例。

```
$cosClient = new Qcloud\Cos\Client(array(
    'region' => '',
    'credentials' => array(
        'secretId' => '',
        'secretKey' => '',
        'token' => ''
    )
));
```

### 上传文件

[](#上传文件)

- 使用 putObject 接口上传文件(最大 5G)
- 使用 Upload 接口分块上传文件

```
# 上传文件
## putObject(上传接口，最大支持上传5G文件)
### 上传内存中的字符串
//bucket 的命名规则为{name}-{appid} ，此处填写的存储桶名称必须为此格式
try {
    $result = $cosClient->putObject(array(
        'Bucket' => $bucket,
        'Key' => $key,
        'Body' => 'Hello World!'));
    print_r($result);
} catch (\Exception $e) {
    echo "$e\n";
}

### 上传文件流
try {
    $result = $cosClient->putObject(array(
        'Bucket' => $bucket,
        'Key' => $key,
        'Body' => fopen($local_path, 'rb')));
    print_r($result);
} catch (\Exception $e) {
    echo "$e\n";
}

### 设置header和meta
try {
    $result = $cosClient->putObject(array(
        'Bucket' => $bucket,
        'Key' => $key,
        'Body' => fopen($local_path, 'rb'),
        'ACL' => 'string',
        'CacheControl' => 'string',
        'ContentDisposition' => 'string',
        'ContentEncoding' => 'string',
        'ContentLanguage' => 'string',
        'ContentLength' => integer,
        'ContentType' => 'string',
        'Expires' => 'mixed type: string (date format)|int (unix timestamp)|\DateTime',
        'Metadata' => array(
            'string' => 'string',
        ),
        'StorageClass' => 'string'));
    print_r($result);
} catch (\Exception $e) {
    echo "$e\n";
}

## Upload(高级上传接口，默认使用分块上传最大支持50T)
### 上传内存中的字符串
try {
    $result = $cosClient->Upload(
        $bucket = $bucket,
        $key = $key,
        $body = 'Hello World!');
    print_r($result);
} catch (\Exception $e) {
    echo "$e\n";
}

### 上传文件流
try {
    $result = $cosClient->Upload(
        $bucket = $bucket,
        $key = $key,
        $body = fopen($local_path, 'rb'));
    print_r($result);
} catch (\Exception $e) {
    echo "$e\n";
}

### 设置header和meta
try {
    $result = $cosClient->Upload(
        $bucket= $bucket,
        $key = $key,
        $body = fopen($local_path, 'rb'),
        $options = array(
            'ACL' => 'string',
            'CacheControl' => 'string',
            'ContentDisposition' => 'string',
            'ContentEncoding' => 'string',
            'ContentLanguage' => 'string',
            'ContentLength' => integer,
            'ContentType' => 'string',
            'Expires' => 'mixed type: string (date format)|int (unix timestamp)|\DateTime',
            'Metadata' => array(
                'string' => 'string',
            ),
            'StorageClass' => 'string'));
    print_r($result);
} catch (\Exception $e) {
    echo "$e\n";
}
```

### 下载文件

[](#下载文件)

- 使用 getObject 接口下载文件
- 使用 getObjectUrl 接口获取文件下载 URL

```
# 下载文件
## getObject(下载文件)
### 下载到内存
//bucket 的命名规则为{name}-{appid} ，此处填写的存储桶名称必须为此格式
try {
    $result = $cosClient->getObject(array(
        'Bucket' => $bucket,
        'Key' => $key));
    echo($result['Body']);
} catch (\Exception $e) {
    echo "$e\n";
}

### 下载到本地
try {
    $result = $cosClient->getObject(array(
        'Bucket' => $bucket,
        'Key' => $key,
        'SaveAs' => $local_path));
} catch (\Exception $e) {
    echo "$e\n";
}

### 指定下载范围
/*
 * Range 字段格式为 'bytes=a-b'
 */
try {
    $result = $cosClient->getObject(array(
        'Bucket' => $bucket,
        'Key' => $key,
        'Range' => 'bytes=0-10',
        'SaveAs' => $local_path));
} catch (\Exception $e) {
    echo "$e\n";
}

### 设置返回header
try {
    $result = $cosClient->getObject(array(
        'Bucket' => $bucket,
        'Key' => $key,
        'ResponseCacheControl' => 'string',
        'ResponseContentDisposition' => 'string',
        'ResponseContentEncoding' => 'string',
        'ResponseContentLanguage' => 'string',
        'ResponseContentType' => 'string',
        'ResponseExpires' => 'mixed type: string (date format)|int (unix timestamp)|\DateTime',
        'SaveAs' => $local_path));
} catch (\Exception $e) {
    echo "$e\n";
}

## getObjectUrl(获取文件Url)
try {
    $signedUrl = $cosClient->getObjectUrl($bucket, $key, '+10 minutes');
    echo $signedUrl;
} catch (\Exception $e) {
    echo "$e\n";
}
```

###  Health Score

64

—

FairBetter than 99% of packages

Maintenance69

Regular maintenance activity

Popularity59

Moderate usage in the ecosystem

Community48

Growing community involvement

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 55.2% 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 ~37 days

Recently: every ~48 days

Total

74

Last Release

529d ago

Major Versions

v1.3.4 → v2.0.02019-09-25

1.3.x-dev → v2.2.12021-07-28

PHP version history (3 changes)v1.0.0PHP &gt;=5.3.3

v1.2.0PHP &gt;=5.3.0

v2.3.2PHP &gt;=5.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/1e6735c4ecc810aa61a07b3507e71c2756fb9e72ba8ba83347c86af34f1e9c67?d=identicon)[lewzylu](/maintainers/lewzylu)

---

Top Contributors

[![lewzylu](https://avatars.githubusercontent.com/u/25299171?v=4)](https://github.com/lewzylu "lewzylu (219 commits)")[![nic12347](https://avatars.githubusercontent.com/u/25325632?v=4)](https://github.com/nic12347 "nic12347 (55 commits)")[![tuuna](https://avatars.githubusercontent.com/u/9778380?v=4)](https://github.com/tuuna "tuuna (50 commits)")[![sy-records](https://avatars.githubusercontent.com/u/33931153?v=4)](https://github.com/sy-records "sy-records (48 commits)")[![Ming2692](https://avatars.githubusercontent.com/u/44095038?v=4)](https://github.com/Ming2692 "Ming2692 (4 commits)")[![1135334967](https://avatars.githubusercontent.com/u/80092554?v=4)](https://github.com/1135334967 "1135334967 (4 commits)")[![konakonall](https://avatars.githubusercontent.com/u/900060?v=4)](https://github.com/konakonall "konakonall (3 commits)")[![yaozongyou](https://avatars.githubusercontent.com/u/590761?v=4)](https://github.com/yaozongyou "yaozongyou (2 commits)")[![freyo](https://avatars.githubusercontent.com/u/13034231?v=4)](https://github.com/freyo "freyo (2 commits)")[![shaunthegeek](https://avatars.githubusercontent.com/u/4971414?v=4)](https://github.com/shaunthegeek "shaunthegeek (1 commits)")[![overtrue](https://avatars.githubusercontent.com/u/1472352?v=4)](https://github.com/overtrue "overtrue (1 commits)")[![Tabll](https://avatars.githubusercontent.com/u/19689327?v=4)](https://github.com/Tabll "Tabll (1 commits)")[![tianyiw2013](https://avatars.githubusercontent.com/u/4644588?v=4)](https://github.com/tianyiw2013 "tianyiw2013 (1 commits)")[![Tinywan](https://avatars.githubusercontent.com/u/14959876?v=4)](https://github.com/Tinywan "Tinywan (1 commits)")[![krwu](https://avatars.githubusercontent.com/u/364298?v=4)](https://github.com/krwu "krwu (1 commits)")[![victorwjwu](https://avatars.githubusercontent.com/u/53364085?v=4)](https://github.com/victorwjwu "victorwjwu (1 commits)")[![wi1dcard](https://avatars.githubusercontent.com/u/25447002?v=4)](https://github.com/wi1dcard "wi1dcard (1 commits)")[![wormcy](https://avatars.githubusercontent.com/u/5145974?v=4)](https://github.com/wormcy "wormcy (1 commits)")[![keacefull](https://avatars.githubusercontent.com/u/8847289?v=4)](https://github.com/keacefull "keacefull (1 commits)")

---

Tags

cosphp-sdkphpqcloudcos

### Embed Badge

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

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

###  Alternatives

[aws/aws-sdk-php

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

6.3k543.5M2.6k](/packages/aws-aws-sdk-php)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

273.0k](/packages/eslazarev-wildberries-sdk)[google/cloud

Google Cloud Client Library

1.2k16.7M57](/packages/google-cloud)[oat-sa/tao-core

TAO core extension

66143.7k124](/packages/oat-sa-tao-core)[onesignal/onesignal-php-api

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com

34216.9k2](/packages/onesignal-onesignal-php-api)[egroupware/egroupware

EGroupware extends a classic groupware with an integrated CRM-system, a secure file-server and Collabora Online Office.

2931.7k](/packages/egroupware-egroupware)

PHPackages © 2026

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