Ceph对象网关S3 API的PHP示例
来源:原创
时间:2020-07-22
作者:脚本小站
分类:云原生
官方文档:官方文档是老版本sdk的示例
http://docs.ceph.org.cn/radosgw/s3/php/
旧sdk的github地址:对应官方文档示例
https://github.com/amazonwebservices/aws-sdk-for-php
新sdk的github地址:
https://github.com/aws/aws-sdk-php
代码示例:
<?php
require 'aws-sdk-for-php/sdk.class.php';
$Connection = new AmazonS3(array(
'key' => '78W0YxxxxxxxB5U9',
'secret' => '80OUcJzux4xxxxxxxxxxxxqJkeb1nWsuG',
// 'canonical_id' => AWS_CANONICAL_ID,
// 'canonical_name' => AWS_CANONICAL_NAME,
));
$Connection->use_ssl = false;
$Connection->ssl_verification = false;
$Connection->set_hostname('s3-fat.demo.com');
$Connection->allow_hostname_override(false);
// Set the S3 class to use objects.dreamhost.com/bucket
// instead of bucket.objects.dreamhost.com
$Connection->enable_path_style();
echo '<pre>';
// 获取bucket名称
$ListResponse = $Connection->list_buckets();
$Buckets = $ListResponse->body->Buckets->Bucket;
foreach ($Buckets as $Bucket) {
echo $Bucket->Name . "\t" . $Bucket->CreationDate . "\n";
}