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 ...
随机推荐
- WPS Office 2019 for Linux来了
难得啊,焕然一新. WPS Office 2019 For Linux更新说明 11.1.0.8392 版本主要更新: 修复wpsoffice进程存在时不能关机的问题 修复WPS文字模块web版式下拖 ...
- IT兄弟连 JavaWeb教程 经典案例3
案例需求:写一个用户登录的html页面有账号和密码,并在登录的Servlet中获取登录的账号和密码,如果账号是abc密码是123则重定向到main.html,否则重定向到login.html. 案例实 ...
- 7天学完Java基础之3/7
API概述 什么叫做API? API(Application Programming lnterface),应用程序编程接口. 所谓API就是值好多的类,好多的方法,JDK给我们提供了很多现成的类,我 ...
- jQuery笔记之工具方法
jQuery 工具方法 $.type()判断数据类型 $.isArray() $.isFunction() $.isWindow()... $.trim()消除空格 $.proxy()改变this指向 ...
- Hexo瞎折腾系列(6) - 将博客同时部署到Github和Coding
前言 由于本人只是将Hexo博客同时部署到 Github 和 Coding.net ,所以这里只介绍怎么同时部署到这两个网站的pages. 之所以选择这两个网站,是因为国外用户可以访问 Github, ...
- Jury Meeting CodeForces - 854D
Jury Meeting CodeForces - 854D 思路:暴力枚举会议开始的那一天(只需用所有向0点飞的航班的那一天+1去枚举即可),并计算所有人此情况下去0点和从0点出来的最小花费. 具体 ...
- 关于BMP
关于BMP位图的资料网上有很多,内容也比较基础.本文实现BMP位图的读取.显示.保存,并对一些重要的问题进行说明(包括字节对齐.内存中的存储顺序.调色板). BMP文件共包括文件头.信息头.调色板(位 ...
- 万能makefile模板
这里一份万能makefile模板,写opencv项目时候使用的. 前提是提前配置好 包管理工具 pkg 然后就不用每次都去 -lopencv_xxx了. ####################### ...
- (025)[系统故障]XP下禁止将串口设备识别成鼠标(转)
很多人都遇到过这种问题:Windows XP启动时将一台连续发送数据的串口设备识别成串口鼠标,自动安装了串口鼠标驱动,而设备因此无法正常工作,而光标则无规律地到处跑.对此问题,Internet上的方法 ...
- Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bhive.session.id%7D_resources
原因:环境变量设置问题 <property> <name>Hive.exec.local.scratchdir</name> <value> ...