转载自:http://www.cnblogs.com/wangxusummer/p/6398772.html

  1. <?php
  2.  
  3. /*
  4. * To change this license header, choose License Headers in Project Properties.
  5. * To change this template file, choose Tools | Templates
  6. * and open the template in the editor.
  7. */
  8.  
  9. define('AWS_KEY', 'input your key');
  10. define('AWS_SECRET_KEY', 'input your secret key');
  11.  
  12. $HOST = 'input your endpoint';
  13.  
  14. // require the amazon sdk for php library
  15. require_once dirname(__FILE__).'/sdk.class.php';
  16.  
  17. // Instantiate the S3 class and point it at the desired host
  18. $s3 = new AmazonS3(array(
  19. 'key' => AWS_KEY,
  20. 'secret' => AWS_SECRET_KEY,
  21. ));
  22. $s3->set_hostname($HOST);
  23. $s3->allow_hostname_override(false);
  24.  
  25. // Set the S3 class to use objects.dreamhost.com/bucket
  26. // instead of bucket.objects.dreamhost.com
  27. $s3->enable_path_style();
  28.  
  29. $bucketname="test_wx";
  30.  
  31. #=========================create_bucket====================
  32. echo str_repeat("=", 30)."create_bucket".str_repeat("=", 30)."\n";
  33. $ret=$s3->create_bucket($bucketname, AmazonS3::REGION_US_E1);
  34. echo print_r($ret,1),"\n";
  35. #=========================list_buckets====================
  36. echo str_repeat("=", 30)."list_buckets".str_repeat("=", 30)."\n";
  37. $ListResponse = $s3->list_buckets();
  38. $Buckets = $ListResponse->body->Buckets->Bucket;
  39. foreach ($Buckets as $Bucket) {
  40. echo $Bucket->Name . "\t" . $Bucket->CreationDate . "\n";
  41. }
  42.  
  43. #=========================create_object====================
  44. echo str_repeat("=", 30)."create_object:".$bucketname.str_repeat("=", 30)."\n";
  45. $s3->create_object($bucketname, 'hello.txt', array(
  46. 'body' => "Hello World!",
  47. 'acl'=>AmazonS3::ACL_PUBLIC,#对对象进行权限分配
  48. ));
  49. echo "create file hello.txt and assign public authority to it \n";
  50. $ret=$s3->create_object($bucketname, 'upload.jpg', array(
  51. 'fileUpload' => dirname(__FILE__)."/j01.png",
  52. 'acl'=>AmazonS3::ACL_PUBLIC,#对对象进行权限分配
  53. ));
  54. echo "return url:".$ret->header['_info']['url'],"\n";
  55. echo "upload file j01.png and assign public authority to it \n";
  56. #=========================set_object_acl 对对象进行权限更改====================
  57. echo str_repeat("=", 30)."set_object_acl:".$bucketname.str_repeat("=", 30)."\n";
  58. $s3->set_object_acl($bucketname,"hello.txt", AmazonS3::ACL_PRIVATE);
  59. echo "change file hello.txt authority \n";
  60.  
  61. #=========================list_objects====================
  62.  
  63. $ObjectsListResponse = $s3->list_objects($bucketname);
  64. $Objects = $ObjectsListResponse->body->Contents;
  65. echo str_repeat("=", 30)."list_objects:".$bucketname.str_repeat("=", 30)."\n";
  66. foreach ($Objects as $Object) {
  67. echo $Object->Key . "\t" . $Object->Size . "\t" . $Object->LastModified . "\n";
  68. }
  69. #=========================get_object_url 获取url====================
  70. echo str_repeat("=", 30)."get_object_url:".$bucketname.str_repeat("=", 30)."\n";
  71. $secret_url = $s3->get_object_url($bucketname, 'j02.jpg', '1 hour');
  72. echo $secret_url . "\n";
  73.  
  74. #=========================DOWNLOAD AN OBJECT====================
  75. #This downloads the object upload.jpg and saves it in d:/
  76. $FileHandle = fopen('d:/upload.jpg', 'w+');
  77. $s3->get_object($bucketname, 'upload.jpg', array(
  78. 'fileDownload' => $FileHandle,
  79. ));
  80. #=========================delete_object====================
  81. echo str_repeat("=", 30)."delete_object".str_repeat("=", 30)."\n";
  82. $s3->delete_object($bucketname, 'hello.txt');
  83. #=========================delete_bucket====================
  84. echo str_repeat("=", 30)."delete_bucket".str_repeat("=", 30)."\n";
  85. $ret=$s3->delete_bucket($bucketname, 1); #This will delete the bucket even if it is not empty.
  86. 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的更多相关文章

  1. 借助亚马逊S3和RapidMiner将机器学习应用到文本挖掘

    本挖掘典型地运用了机器学习技术,例如聚类,分类,关联规则,和预测建模.这些技术揭示潜在内容中的意义和关系.文本发掘应用于诸如竞争情报,生命科学,客户呼声,媒体和出版,法律和税收,法律实施,情感分析和趋 ...

  2. Ceph RGW服务 使用s3 java sdk 分片文件上传API 报‘SignatureDoesNotMatch’ 异常的定位及规避方案

    import java.io.File;   import com.amazonaws.AmazonClientException; import com.amazonaws.auth.profile ...

  3. 亚马逊S3下载上传文件

    引用网址: http://www.jxtobo.com/27697.html 下载 CloudBerry Explorer http://www.cloudberrylab.com/download- ...

  4. AWS CLI使用s3

    aws CLI是什么东西,暂且先不去了解,目前的需求是s3. 我在Jenkins上创建一个bucket,然后申请access_key,然后就可以使用s3来存储数据了.也就是说,s3就是一个网盘. 1. ...

  5. AWS S3 CLI的权限bug

    使用AWS CLI在S3上创建了一个bucket,上传文件的时候报以下错误: A client error (AccessDenied) occurred when calling the Creat ...

  6. ceph rgw s3 java sdk 上传大文件分批的方法

    Using the AWS Java SDK for Multipart Upload (High-Level API) Topics Upload a File Abort Multipart Up ...

  7. 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 ...

  8. Android开发-mac上使用三星S3做真机调试

    之前一直未使用真机进行Android开发,为准备明天的培训,拿出淘汰下来的s3准备环境,竟然发现无法连接mac,度娘一番找到答案,如下:mac 系统开发android,真机调试解决方案(无数的坑之后吐 ...

  9. AWS CLI 中使用S3存储

    登录 通过控制面板, 在S3管理器中创建一个新的bucket 所有AWS服务 -> 安全&身份 -> IAM -> 组, 创建一个新的组, 例如 "s3-user& ...

  10. 电源相关知识—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 ...

随机推荐

  1. Luogu P2278 [HNOI2003]操作系统【优先队列/重载运算符/模拟】 By cellur925

    题目传送门 本来是照着二叉堆的题去做的...没想到捡了个模拟...不过模拟我都不会...我好弱啊... 其实核心代码并不长,比辰哥的标程短到不知哪里去...但是思路需要清晰. 读题的时候我明白,当有优 ...

  2. Python入门小练习-001-备份文件

    练习适用于LINUX,类Unix系统,一步一个脚印提高Python . 001. 类Unix系统中用zip命令将文件压缩备份至 /temporary/ 目录下: import os import ti ...

  3. 排序二叉树 HDOJ 5444 Elven Postman

    题目传送门 题意:给出线性排列的树,第一个数字是根节点,后面的数如果当前点小或相等往左走,否则往右走,查询一些点走的路径 分析:题意略晦涩,其实就是排序二叉树!1<<1000 普通数组开不 ...

  4. subline应用之常用插件

    汉化插件:ChineseLocalzations IMESupport插件:解决软件输入法跟随问题 SublimeREPL插件:可以用于运行和调试一些需要交互的程序如python SublimeCod ...

  5. yum卸载遇到的问题--待解决

    系统版本是 [root@master ~]# uname -a Linux master -.el6.x86_64 # SMP Sun Nov :: EST x86_64 x86_64 x86_64 ...

  6. memcache的分布式配置

    public static class MemcacheHelper { private static MemcachedClient mc; static MemcacheHelper() { St ...

  7. AJPFX总结java开发常用类(包装,数字处理集合等)(二)

    二:进军集合类 集合其实就是存放对象的容器,专业点说就是集合是用来存储和管理其他对象的对象,即对象的容器.集合可以扩容,长度可变,可以存储多种类型的数据,而数组长度不可变,只能存储单一类型的元素 用一 ...

  8. 简要记录下localStorage在项目中的应用之一

    localStorage作为HTML5本地存储web storage特性的API之一,主要作用是将数据保存在客户端中.localStorage保存的数据,一般情况下是永久保存的,也就是说只要采用loc ...

  9. poj2139 Six Degrees of Cowvin Bacon

    思路: floyd 实现: #include <iostream> #include <cstdio> #include <cstring> #include &l ...

  10. 字符串、数组、json

    一.字符串 string 1.字符串的定义: (1).var s="haha"; (2).var s=new string ("hello") 对象形式定义 2 ...