highlight js

2012年9月19日水曜日

AWS S3バケットに格納するメモ

http://docs.amazonwebservices.com/AWSSDKforPHP/latest/index.html#i=AmazonS3

# sudo pear channel-discover pear.amazonwebservices.com
# sudo pear install aws/sdk
とやるか、PHP SDKをDLしてきて、適宜設置する。
# cp config-sample.inc.php config.inc.php
として、key, secretを設定



include_once "AWSSDKforPHP/sdk.class.php";
include_once "AWSSDKforPHP/config.inc.php";

$s3 = new AmazonS3();

$aws_upfile = "test/test-".time().".txt"; 

# test-bucketは既に生成済みのbucket
# AmazonS3::ACL_PUBLIC で公開ファイルとして。
$res = $s3->create_object("test-bucket", $aws_upfile, array('fileUpload' => $filename, 'acl' => AmazonS3::ACL_PUBLIC));

# UPしたファイルの公開URLの取得
$url = $s3->get_object_url("test-bucket", $aws_upfile);
# UPしたファイル一覧
$list = $s3->get_object_list("test-bucket");