AWSのS3を使用していて、bucketにある画像をブラウザに表示したいのですが、AWSのDocumentにあった以下のコードを記載しても、うまく表示されません。PHP Parse error: syntax error, unexpected 'use' (T_USE)
のエラーが表示されてしまいます。解決策をご教示いただけると幸いです。
<状況>
・AWS SDK for PHPはインストール済み
・PHP のバージョンは5.6
・indexファイルにrequire 'vendor/autoload.php';
を記載(useのそばに記載してもダメでした)
<参考>
http://docs.aws.amazon.com/ja_jp/AmazonS3/latest/dev/RetrieveObjSingleOpPHP.html
php
1<?php 2 3// Include the AWS SDK using the Composer autoloader. 4require 'vendor/autoload.php'; 5 6use Aws\S3\S3Client; 7use Aws\S3\Exception\S3Exception; 8 9$bucket = '*** Your Bucket Name ***'; 10$keyname = '*** Your Object Key ***'; 11 12// Instantiate the client. 13$s3 = S3Client::factory(); 14 15try { 16 // Get the object 17 $result = $s3->getObject(array( 18 'Bucket' => $bucket, 19 'Key' => $keyname 20 )); 21 22 // Display the object in the browser 23 header("Content-Type: {$result['ContentType']}"); 24 echo $result['Body']; 25} catch (S3Exception $e) { 26 echo $e->getMessage() . "\n";
あなたの回答
tips
プレビュー