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 ...
随机推荐
- Luogu P2278 [HNOI2003]操作系统【优先队列/重载运算符/模拟】 By cellur925
题目传送门 本来是照着二叉堆的题去做的...没想到捡了个模拟...不过模拟我都不会...我好弱啊... 其实核心代码并不长,比辰哥的标程短到不知哪里去...但是思路需要清晰. 读题的时候我明白,当有优 ...
- Python入门小练习-001-备份文件
练习适用于LINUX,类Unix系统,一步一个脚印提高Python . 001. 类Unix系统中用zip命令将文件压缩备份至 /temporary/ 目录下: import os import ti ...
- 排序二叉树 HDOJ 5444 Elven Postman
题目传送门 题意:给出线性排列的树,第一个数字是根节点,后面的数如果当前点小或相等往左走,否则往右走,查询一些点走的路径 分析:题意略晦涩,其实就是排序二叉树!1<<1000 普通数组开不 ...
- subline应用之常用插件
汉化插件:ChineseLocalzations IMESupport插件:解决软件输入法跟随问题 SublimeREPL插件:可以用于运行和调试一些需要交互的程序如python SublimeCod ...
- yum卸载遇到的问题--待解决
系统版本是 [root@master ~]# uname -a Linux master -.el6.x86_64 # SMP Sun Nov :: EST x86_64 x86_64 x86_64 ...
- memcache的分布式配置
public static class MemcacheHelper { private static MemcachedClient mc; static MemcacheHelper() { St ...
- AJPFX总结java开发常用类(包装,数字处理集合等)(二)
二:进军集合类 集合其实就是存放对象的容器,专业点说就是集合是用来存储和管理其他对象的对象,即对象的容器.集合可以扩容,长度可变,可以存储多种类型的数据,而数组长度不可变,只能存储单一类型的元素 用一 ...
- 简要记录下localStorage在项目中的应用之一
localStorage作为HTML5本地存储web storage特性的API之一,主要作用是将数据保存在客户端中.localStorage保存的数据,一般情况下是永久保存的,也就是说只要采用loc ...
- poj2139 Six Degrees of Cowvin Bacon
思路: floyd 实现: #include <iostream> #include <cstdio> #include <cstring> #include &l ...
- 字符串、数组、json
一.字符串 string 1.字符串的定义: (1).var s="haha"; (2).var s=new string ("hello") 对象形式定义 2 ...