PHP-SDK
S3-PHP-SDK?
Boto-PHP版(ban)本是(shi)AWS的PHP接口(kou),調用相關API, 即可訪問(wen)Amazon S3或其他(ta)兼容S3的存儲服務(wu)。
前置條件?
- 如果您還不了解COS,請參考對象存儲服務;
- 使用SDK需要擁有有效的密鑰對(包括AccessKeyId和AccessKeySecret)進行簽名認證,請在控制臺界面獲取該密鑰對;
適用系統?
Mac OS X,Windows,Linux等
環境設置?
1、安裝PHP
查看(kan)是否存在老(lao)的(de)PHP版本
yum list installed | grep php如果存在,先刪除
yum remove php* php-commonrpm安裝php7相應的yum源
rpm -Uvh //mirror.webtatic.com/yum/el7/webtatic-release.rpm安裝php7
yum install php70w安(an)裝依賴庫php-xml
yum install php70w-xml
2、安(an)裝(zhuang)Composer和(he)依賴包
mkdir cos-php-demo
cd cos-php-demo
curl -sS //getcomposer.org/installer | php
編輯composer.json,內容如下:
{
"require": {
"aws/aws-sdk-php": "2.*"
}
}
執行?php composer.phar install,完成依賴包(bao)的下載(zai)安(an)裝
使用PHP-SDK?
1、列出所有桶
編輯list-bucket.php,內容(rong)如(ru)下:
<?php
require "vendor/autoload.php";
use Aws\Common\Enum\Region;
use Aws\S3\S3Client;
// 1. 初始化S3客戶端
$client = S3Client::factory(array(
'credentials' => array(
'key' => "YOUR_ACCESS_KEY_ID",
'secret' => "YOU_SECRET_ACCESS_KEY",
),
"scheme" => "http",
"version" => "latest",
"endpoint"=> "//s3-cn-suzhou.cn-henji.com",
));
// 2、列(lie)出所有Bucket
$buckets = $client->listBuckets()->toArray();
foreach($buckets as $bucket){
print_r($bucket);
}
執行腳本php list-bucket.php后,輸出:
mybucket-1
mybucket-2
mybucket-3
2、更多操作
請見鏈接: