doucan1979 2011-09-12 14:22
浏览 144
已采纳

如何使用php和Amazon S3 sdk下载文件?

I'm trying to make it so that my script will show test.jpg in an Amazon S3 bucket through php. Here's what I have so far:

require_once('library/AWS/sdk.class.php');

$s3 = new AmazonS3($key, $secret);

$objInfo = $s3->get_object_headers('my_bucket', 'test.jpg');
$obj = $s3->get_object('my_bucket', 'test.jpg', array('headers' => array('content-disposition' => $objInfo->header['_info']['content_type'])));

echo $obj->body;

This just dumps out the file data on the page. I think I need to also send the content-disposition header, which I thought was being done in the get_object() method, but it isn't.

Note: I'm using the SDK available here: http://aws.amazon.com/sdkforphp/

  • 写回答

5条回答 默认 最新

  • duanqi6007 2011-09-12 14:52
    关注

    Got it to work by echo'ing out the content-type header before echo'ing the $object body.

    $objInfo = $s3->get_object_headers('my_bucket', 'test.jpg');
    $obj = $s3->get_object('my_bucket', 'test.jpg');
    
    header('Content-type: ' . $objInfo->header['_info']['content_type']);
    echo $obj->body;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮