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

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

larva/cos-sdk-v5
================

PHP SDK for QCloud COS

2.5.0(4y ago)0518MITPHPPHP ^7.4 | ^8.0

Since Feb 19Pushed 4y agoCompare

[ Source](https://github.com/larvatecn/cos-php-sdk-v5)[ Packagist](https://packagist.org/packages/larva/cos-sdk-v5)[ RSS](/packages/larva-cos-sdk-v5/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

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

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

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

[![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/e2c1a62fdc05b0e976290fa079881763b0c538778772ee317ca232064732977a/68747470733a2f2f7472617669732d63692e636f6d2f74656e63656e7479756e2f636f732d7068702d73646b2d76352e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/tencentyun/cos-php-sdk-v5)[![codecov](https://camo.githubusercontent.com/a233646c1001767d98fb66b96c71f52c47d8f3dcfd8aa163b294e027ee88524a/68747470733a2f2f636f6465636f762e696f2f67682f74656e63656e7479756e2f636f732d7068702d73646b2d76352f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/tencentyun/cos-php-sdk-v5)

环境准备
----

[](#环境准备)

- PHP 7.2+ 您可以通过`php -v`命令查看当前的 PHP 版本。
- cURL 扩展 您可以通过`php -m`命令查看 cURL 扩展是否已经安装好。

> - Ubuntu 系统中，您可以使用 apt-get 包管理器安装 PHP 的 cURL 扩展，安装命令如下。

```
sudo apt-get install php-curl

```

> - CentOS 系统中，您可以使用 yum 包管理器安装 PHP 的 cURL 扩展。

```
sudo yum install php-curl

```

#### 安装步骤：

[](#安装步骤)

使用 Composer 安装，执行以下命令。

```
composer require qcloud/cos-sdk-v5 -vv

```

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

快速入门
----

[](#快速入门)

可参照 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) {
    print_r($e);
}
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity58

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

Total

2

Last Release

1557d ago

PHP version history (2 changes)2.1.0PHP ^7.2 | ^8.0

2.5.0PHP ^7.4 | ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/534cdb651e8c806590fa945c6b5a18f361613848e890db1349f4a9fbcae1a650?d=identicon)[xutongle](/maintainers/xutongle)

---

Top Contributors

[![xutl](https://avatars.githubusercontent.com/u/20939388?v=4)](https://github.com/xutl "xutl (7 commits)")

---

Tags

phpqcloudcos

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[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)[qcloud_sts/qcloud-sts-sdk

PHP SDK for QCloud STS

10173.3k9](/packages/qcloud-sts-qcloud-sts-sdk)

PHPackages © 2026

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