php S3
转载自:http://www.cnblogs.com/wangxusummer/p/6398772.html
<?php /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/ define('AWS_KEY', 'input your key');
define('AWS_SECRET_KEY', 'input your secret key'); $HOST = 'input your endpoint'; // require the amazon sdk for php library
require_once dirname(__FILE__).'/sdk.class.php'; // Instantiate the S3 class and point it at the desired host
$s3 = new AmazonS3(array(
'key' => AWS_KEY,
'secret' => AWS_SECRET_KEY,
));
$s3->set_hostname($HOST);
$s3->allow_hostname_override(false); // Set the S3 class to use objects.dreamhost.com/bucket
// instead of bucket.objects.dreamhost.com
$s3->enable_path_style(); $bucketname="test_wx"; #=========================create_bucket====================
echo str_repeat("=", 30)."create_bucket".str_repeat("=", 30)."\n";
$ret=$s3->create_bucket($bucketname, AmazonS3::REGION_US_E1);
echo print_r($ret,1),"\n";
#=========================list_buckets====================
echo str_repeat("=", 30)."list_buckets".str_repeat("=", 30)."\n";
$ListResponse = $s3->list_buckets();
$Buckets = $ListResponse->body->Buckets->Bucket;
foreach ($Buckets as $Bucket) {
echo $Bucket->Name . "\t" . $Bucket->CreationDate . "\n";
} #=========================create_object====================
echo str_repeat("=", 30)."create_object:".$bucketname.str_repeat("=", 30)."\n";
$s3->create_object($bucketname, 'hello.txt', array(
'body' => "Hello World!",
'acl'=>AmazonS3::ACL_PUBLIC,#对对象进行权限分配
));
echo "create file hello.txt and assign public authority to it \n";
$ret=$s3->create_object($bucketname, 'upload.jpg', array(
'fileUpload' => dirname(__FILE__)."/j01.png",
'acl'=>AmazonS3::ACL_PUBLIC,#对对象进行权限分配
));
echo "return url:".$ret->header['_info']['url'],"\n";
echo "upload file j01.png and assign public authority to it \n";
#=========================set_object_acl 对对象进行权限更改====================
echo str_repeat("=", 30)."set_object_acl:".$bucketname.str_repeat("=", 30)."\n";
$s3->set_object_acl($bucketname,"hello.txt", AmazonS3::ACL_PRIVATE);
echo "change file hello.txt authority \n"; #=========================list_objects==================== $ObjectsListResponse = $s3->list_objects($bucketname);
$Objects = $ObjectsListResponse->body->Contents;
echo str_repeat("=", 30)."list_objects:".$bucketname.str_repeat("=", 30)."\n";
foreach ($Objects as $Object) {
echo $Object->Key . "\t" . $Object->Size . "\t" . $Object->LastModified . "\n";
}
#=========================get_object_url 获取url====================
echo str_repeat("=", 30)."get_object_url:".$bucketname.str_repeat("=", 30)."\n";
$secret_url = $s3->get_object_url($bucketname, 'j02.jpg', '1 hour');
echo $secret_url . "\n"; #=========================DOWNLOAD AN OBJECT====================
#This downloads the object upload.jpg and saves it in d:/
$FileHandle = fopen('d:/upload.jpg', 'w+');
$s3->get_object($bucketname, 'upload.jpg', array(
'fileDownload' => $FileHandle,
));
#=========================delete_object====================
echo str_repeat("=", 30)."delete_object".str_repeat("=", 30)."\n";
$s3->delete_object($bucketname, 'hello.txt');
#=========================delete_bucket====================
echo str_repeat("=", 30)."delete_bucket".str_repeat("=", 30)."\n";
$ret=$s3->delete_bucket($bucketname, 1); #This will delete the bucket even if it is not empty.
echo print_r($ret,1),"\n";
sdk.class.php library下载地址:
https://github.com/amazonwebservices/aws-sdk-for-php
参考地址:
http://docs.ceph.com/docs/master/radosgw/s3/php/#change-an-object-s-acl
php S3的更多相关文章
- 借助亚马逊S3和RapidMiner将机器学习应用到文本挖掘
本挖掘典型地运用了机器学习技术,例如聚类,分类,关联规则,和预测建模.这些技术揭示潜在内容中的意义和关系.文本发掘应用于诸如竞争情报,生命科学,客户呼声,媒体和出版,法律和税收,法律实施,情感分析和趋 ...
- Ceph RGW服务 使用s3 java sdk 分片文件上传API 报‘SignatureDoesNotMatch’ 异常的定位及规避方案
import java.io.File; import com.amazonaws.AmazonClientException; import com.amazonaws.auth.profile ...
- 亚马逊S3下载上传文件
引用网址: http://www.jxtobo.com/27697.html 下载 CloudBerry Explorer http://www.cloudberrylab.com/download- ...
- AWS CLI使用s3
aws CLI是什么东西,暂且先不去了解,目前的需求是s3. 我在Jenkins上创建一个bucket,然后申请access_key,然后就可以使用s3来存储数据了.也就是说,s3就是一个网盘. 1. ...
- AWS S3 CLI的权限bug
使用AWS CLI在S3上创建了一个bucket,上传文件的时候报以下错误: A client error (AccessDenied) occurred when calling the Creat ...
- ceph rgw s3 java sdk 上传大文件分批的方法
Using the AWS Java SDK for Multipart Upload (High-Level API) Topics Upload a File Abort Multipart Up ...
- cosbench read异常解决办法。 Unable to verify integrity of data download. Client calculated content hash didn't match hash calculated by Amazon S3. The data may be corrupt.
问题:cosbench read测试failed 报错如下 Cosbench v0.4.2.c4 against Ceph (Hammer) / radosgw / HAproxy's HTTP en ...
- Android开发-mac上使用三星S3做真机调试
之前一直未使用真机进行Android开发,为准备明天的培训,拿出淘汰下来的s3准备环境,竟然发现无法连接mac,度娘一番找到答案,如下:mac 系统开发android,真机调试解决方案(无数的坑之后吐 ...
- AWS CLI 中使用S3存储
登录 通过控制面板, 在S3管理器中创建一个新的bucket 所有AWS服务 -> 安全&身份 -> IAM -> 组, 创建一个新的组, 例如 "s3-user& ...
- 电源相关知识—S0、S1(POS)、S2、S3(STR)、 S4、S5、睡眠、休眠、待机
转 http://blog.sina.com.cn/s/blog_52f28dde0100l3ci.html APM https://en.wikipedia.org/wiki/Advanced_Po ...
随机推荐
- 基于.NetCore和ABP框架如何让Windows服务执行Quartz定时作业
demo地址:ABP.WindowsService 该系列文章启发自 How to: Create a Windows Service that schedules jobs, logs and is ...
- Springboot配置类
配置类 MyAppConfig import com.test.springboot.service.HelloService; import org.springframework.context ...
- Jenkins持续集成多任务之MultiJob
项目实践中,我们可能需要在多个任务发布成功后在执行某个任务,这里就需要用到MultiJob这个插件. 案例场景:有3个任务:A.B.C,其中C任务需要等A和B执行成功后才会执行,那么就要先执行A和B, ...
- 一个Nice的生活主题博客模板
https://www.bitcron.com/ https://api.bitcron.com/ https://chopstack.com/
- [洛谷P4185] [USACO18JAN]MooTube
题目链接: 传送门 题意: 给定一颗N个节点的树,定义两点距离为他们之间路径中边权最小值. Q次询问K,V,询问到V距离>=K的点有多少(不含V) 呃呃呃呃考试的时候直奔了T3,结果公式推挂了( ...
- 洛谷 P3935 Calculating
虽然对这道题没有什么帮助,但是还是记一下:约数个数也是可以线性筛的 http://www.cnblogs.com/xzz_233/p/8365414.html 测正确性题目:https://www.l ...
- Maven聚合模式
项目的打包类型:pom.jar.war 项目中一般使用maven进行模块管理,每个模块下对应都有一个pom文件,pom文件中维护了各模块之间的依赖和继承关系.项目模块化可以将通用的部分抽离出来,方便重 ...
- 一个因xdata声明引起的隐含错误
我们知道一般增强型c51自身的RAM只有128BYTES,根本不够用,所以一般在定义全局变量,静态变量时都要用XDATA作为关键字修饰数据的的存储类型.但要注意的是,定义和声明一定要一致,不然出现错误 ...
- D. Tavas and Malekas DFS模拟 + kmp + hash || kmp + hash
http://codeforces.com/contest/535/problem/D 如果真的要把m个串覆盖上一个串上面,是可以得,不会超时. 要注意到一点,全部覆盖后再判断时候合法,和边放边判断, ...
- Windows下降权MYSQL和apche的运行级别(普通用户权限运行)
1.MYSQL的降权运行 新建立一个用户比如mysql net user mysql microsoft /add net localgroup users mysql /del 不属于任何组 ...