如何使用PHP SDK v3从Amazon S3显示文本文件的内容

时间:2016-12-08 08:24:26

标签: php amazon-web-services amazon-s3 aws-php-sdk

我对使用哪个函数来显示在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>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

这是使用php SDK从S3获取文本文件内容的简单代码

$w.onReady(function () {
   let fadeOptions = {
        "duration":   500,
        "delay":      500
    };      
    $w('#image4').onMouseOut( (Event) => {
      $w('#image4').show('fade', fadeOptions);
    } );
    $w('#image4').onMouseIn( (Event) => {
      $w('#image4').hide('fade', fadeOptions);
    } );
 });