【问题标题】:trying to save image in amazon s3 but image not getting saved试图在 amazon s3 中保存图像但图像未保存
【发布时间】:2013-12-20 06:13:58
【问题描述】:

我正在尝试将图像从图像 url 保存到 amazon s3,但图像是在存储桶中创建的,但图像未显示在浏览器中,显示消息“图像无法显示,因为它包含错误。

这是我的代码: require_once("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生成的图片路径

【问题讨论】:

    标签: php image amazon-web-services amazon-s3


    【解决方案1】:

    改变这一行

    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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-20
      • 2018-08-11
      • 2013-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多