![](/img/trans.png)
[英]Amazon S3 how to validate Access Key Id and Secret Access Key? PHP SDK v3
[英]How to display contents of text file from Amazon S3 using PHP SDK v3
對於使用哪個功能來顯示位於bucketname / plain.txt位置的文本文件,我感到困惑。
有人可以告訴我我應該怎么做嗎?
<?php ?> <html> <head><title>PHP says hello</title></head> <body> <b> <?php $client = new Aws\\S3\\S3Client([/** options **/]); // Register the stream wrapper from an S3Client object $client->registerStreamWrapper(); // Download the body of the "key" object in the "bucket" bucket $data = file_get_contents('s3://vetri/plain.txt'); // Open a stream in read-only mode if ($stream = fopen('s3://vetri/plain.txt', 'r')) { // While the stream is still open while (!feof($stream)) { // Read 1024 bytes from the stream echo fread($stream, 1024); } // Be sure to close the stream resource when you're done with it fclose($stream); } ?> </b> </body> </html>
這是使用php SDK從S3獲取文本文件內容的簡單代碼
<?php
// Include the SDK using the composer autoloader
require '/Users/tn/vendor/autoload.php';
$s3 = new Aws\S3\S3Client([
'region' => 'your region',
'version' => 'latest',
'credentials' => [
'key' => "Your Key Id",
'secret' => "Your secret access key",
]
]);
// Send a PutObject request and get the result object.
$key = 'name of the file you want to read';
$result = $s3->getObject([
'Bucket' => 'name of the bucket',
'Key' => $key,
'Body' => 'this is the body!',
]);
// Print the body of the result by indexing into the result object.
echo result['Body'];
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.