alibabacloud/oss-v2
Composer 安装命令:
composer require alibabacloud/oss-v2
包简介
Aliyun OSS SDK for PHP v2
README 文档
README
alibabacloud-oss-php-sdk-v2 is the v2 of the OSS SDK for the PHP programming language
简体中文
About
- This PHP SDK is based on the official APIs of Alibaba Cloud OSS.
- Alibaba Cloud Object Storage Service (OSS) is a cloud storage service provided by Alibaba Cloud, featuring massive capacity, security, a low cost, and high reliability.
- The OSS can store any type of files and therefore applies to various websites, development enterprises and developers.
- With this SDK, you can upload, download and manage data on any app anytime and anywhere conveniently.
Running Environment
- PHP 7.4 or above.
Installing
Install the sdk through composer
If you use the composer to manage project dependencies, run the following command in your project's root directory:
$ composer require alibabacloud/oss-v2
You can also declare the dependency on Alibaba Cloud OSS SDK for PHP v2 in the composer.json file.
"require": { "alibabacloud/oss-v2": "*" }
Install from the PHAR File directly
$ require_once '/path/to/alibabacloud-oss-php-sdk-v2-{version}.phar'
Getting Started
List Bucket
<?php use AlibabaCloud\Oss\V2 as Oss; $region = 'cn-hangzhou'; // Loading credentials values from the environment variables $credentialsProvider = new Oss\Credentials\EnvironmentVariableCredentialsProvider(); // Using the SDK's default configuration $cfg = Oss\Config::loadDefault(); $cfg->setCredentialsProvider($credentialsProvider); $cfg->setRegion($region); $client = new Oss\Client($cfg); // Create the Paginator for the ListBuckets operation $paginator = new Oss\Paginator\ListBucketsPaginator($client); $iter = $paginator->iterPage(new Oss\Models\ListBucketsRequest()); // Iterate through the bucket pages foreach ($iter as $page) { foreach ($page->buckets ?? [] as $bucket) { print("Bucket: $bucket->name, $bucket->location\n"); } }
List Objects
<?php use AlibabaCloud\Oss\V2 as Oss; $region = 'cn-hangzhou'; $bucket = 'your bucket name'; // Loading credentials values from the environment variables $credentialsProvider = new Oss\Credentials\EnvironmentVariableCredentialsProvider(); // Using the SDK's default configuration $cfg = Oss\Config::loadDefault(); $cfg->setCredentialsProvider($credentialsProvider); $cfg->setRegion($region); $client = new Oss\Client($cfg); # Create the Paginator for the ListBuckets operation $paginator = new Oss\Paginator\ListObjectsV2Paginator($client); $iter = $paginator->iterPage(new Oss\Models\ListObjectsV2Request($bucket)); // Iterate through the object pages foreach ($iter as $page) { foreach ($page->contents ?? [] as $object) { print("Object: $object->key, $object->type, $object->size\n"); } }
Put Object
<?php use AlibabaCloud\Oss\V2 as Oss; $region = 'cn-hangzhou'; $bucket = 'your bucket name'; $key = 'your object name'; // Loading credentials values from the environment variables $credentialsProvider = new Oss\Credentials\EnvironmentVariableCredentialsProvider(); // Using the SDK's default configuration $cfg = Oss\Config::loadDefault(); $cfg->setCredentialsProvider($credentialsProvider); $cfg->setRegion($region); $client = new Oss\Client($cfg); $data = 'Hello OSS'; $request = new Oss\Models\PutObjectRequest($bucket, $key); $request->body = Oss\Utils::streamFor($data); $result = $client->putObject($request); printf( 'status code:'. $result->statusCode .PHP_EOL. 'request id:'. $result->requestId .PHP_EOL. 'etag:'. $result->etag. PHP_EOL );
Complete Example
More example projects can be found in the sample folder
Running Example
- Run
composer installto download the dependent libraries.- Go to the sample code folder
sample。- Configure credentials values from the environment variables, like
export OSS_ACCESS_KEY_ID="your access key id",export OSS_ACCESS_KEY_SECRET="your access key secrect"- Take ListBuckets.php as an example,run
php ListBuckets.php --region cn-hangzhoucommand。
Resources
Developer Guide - Use this document to learn how to get started and use this sdk.
License
- Apache-2.0, see license file
alibabacloud/oss-v2 适用场景与选型建议
alibabacloud/oss-v2 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 36.84k 次下载、GitHub Stars 达 18, 最近一次更新时间为 2025 年 01 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 alibabacloud/oss-v2 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 alibabacloud/oss-v2 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 36.84k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 20
- 点击次数: 34
- 依赖项目数: 10
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2025-01-03