试图在amazons3中保存图像,但图像未保存


trying to save image in amazon s3 but image not getting saved

我正试图将图像从图像url保存到amazons3,但图像是在bucket中创建的,但浏览器中没有显示图像,显示消息"图像无法显示,因为它包含错误。

这是我的代码:require_one("aws/aws autoloader.php");

        // Amazon S3
        use Aws'S3'S3Client;
        // Create an Amazon S3 client object
        $s3Client = S3Client::factory(array(
            'key'    => 'XXXXXXXXXXXX',
            'secret' => 'XXXXXXXXX'
        ));
        // Register the stream wrapper from a client object
        $s3Client->registerStreamWrapper();
        // Save Thumbnail
        $s3Path = "s3://smmrescueimages/";
        $s3Stream = fopen($s3Path . 'gt.jpg', 'w');
        fwrite($s3Stream, 'http://sippy.in/gt.jpg');
        @fclose($s3Stream);
        echo "done";

这是生成的图像路径https://s3.amazonaws.com/smmrescueimages/gt.jpg

更改此行

fwrite($s3Stream, 'http://sippy.in/gt.jpg');

fwrite($s3Stream, file_get_contents('http://sippy.in/gt.jpg'));

否则,将图像二进制文件的url字符串即时保存到文件中。

不要使用@来防止php函数的错误消息!只需检查是否存在有效的处理程序

$s3Stream = fopen($s3Path . 'gt.jpg', 'w');
if( $s3Stream ) {
    fwrite($s3Stream, file_get_contents('http://sippy.in/gt.jpg'));
    fclose($s3Stream);
}