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 ...
随机推荐
- 黑客攻防技术宝典web实战篇:攻击用户·其他技巧习题
猫宁!!! 参考链接:http://www.ituring.com.cn/book/885 随书答案. 1. 已知一项应用程序功能将一个查询字符串参数的内容插入到某个 HTTP 重定向的 Locati ...
- Zookeeper的多节点集群详细启动步骤(3或5节点)
分为 (1)分别去3或5节点上去启动Zookeeper进程 (2)自己写个脚本,直接在主节点上去启动Zookeeper进程. (1)分别去3或5节点上去启动Zookeeper进程 第一步: [hado ...
- hdu1151 Air Raid 基础匈牙利
#include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> ...
- the little schemer 笔记(10.1)
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 China Mainla ...
- Sublime Text3 配置C++(附oj刷题常用模板)
# 下载对应平台的sublime sublime最新版下载, 字体样式个人喜欢Consolas, 另附注册码: -– BEGIN LICENSE -– TwitterInc 200 User Lice ...
- Hibernate通过实体对象对应数据库表信息
Hibernate通过实体对象对应数据库表信息,包括:数据库表名称.主键列名.非主键列名等. 获取对象映射缓存管理类: AbstractEntityPersister aep = (AbstractE ...
- 亚马逊左侧菜单延迟z三角 jquery插件jquery.menu-aim.js源码解读
关于亚马逊的左侧菜单延迟,之前一直不知道它的实现原理.梦神提到了z三角,我也不知道这是什么东西.13号那天很有空,等领导们签字完我就可以走了.下午的时候,找到了一篇博客:http://jayuh.co ...
- hihocoder1736 最大的K-偏差排列
思路: 容易写错的贪心题. 实现: #include <bits/stdc++.h> using namespace std; int main() { int n, k; while ( ...
- asp.net 中文部分显示问号
很神奇的事情,今天部署了一个网站,页面从数据读取新闻后,有些新闻标题全部显示问题号,有几个新闻能正确显示汉字,然后查看新闻页面又能正常显示汉字. 解决办法: 在异常的页面上加上 < %@ COD ...
- 一条陌生的出路【过往d心声】
一条陌生的出路 Vashon的心声 人生就像一列车,车上总有形形色色的人穿梭往来.你也可能会在车上遇到很多你以为有缘分的人,但是车也会有停下来的时候,总会有人从人生这列车上上下下,当你下去的时候你挥挥 ...