$ curl -sS https://getcomposer.org/installer | php
$ php composer.phar require aws/aws-sdk-php
ファイルの読み込み
require_once “vendor/autoload.php”;
$bucket = ‘hoge’;
$key = ”;
$secret = ”;
$file = “test.txt”;
$s3client = new Aws\S3\S3Client([
‘credentials’ => [
‘key’ => $key,
‘secret’ => $secret,
],
‘region’ => ‘ap-northeast-1’,
‘version’ => ‘latest’,
]);
$s3client->registerStreamWrapper();
$stream = fopen(‘s3://hoge/test.txt’, ‘r’);
if (FALSE === $stream){
exit(“Failed to open”);
}
while (!feof($stream)){
echo fread($stream, 1024);
}
fclose($stream);
[/code]
S3のファイルの追記
require_once "vendor/autoload.php"; $bucket = 'hoge'; $key = 'hogehoge'; $secret = 'ccccc'; $file = "aaa.txt"; $s3client = new Aws\S3\S3Client([ 'credentials' => [ 'key' => $key, 'secret' => $secret, ], 'region' => 'ap-northeast-1', 'version' => 'latest', ]); $s3client->registerStreamWrapper(); $stream = fopen('s3://'. $bucket .'/test/' . $file, 'a'); fwrite($stream, 'hogehoge2' . PHP_EOL); fclose($stream);
できるか不安だったけど、割と簡単に実装できて安堵