怎样下载使用PHP和Amazon S3的SDK文件? [英] How do I download a file with php and the Amazon S3 sdk?
本文介绍了怎样下载使用PHP和Amazon S3的SDK文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图让这个我的脚本将通过PHP显示test.jpg放在一个Amazon S3存储桶。 这是我到目前为止有:
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;
这只是转储了页面上的文件数据。我想我还需要发送内容处置标题,我还以为是被中的get_object()方法完成的,但事实并非如此。
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.
注:我使用的是现有的SDK在这里: http://aws.amazon.com/sdkforphp/
Note: I'm using the SDK available here: http://aws.amazon.com/sdkforphp/
推荐答案
明白了通过echo'ing出来的Content-Type头echo'ing的$对象身体之前工作。
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;
这篇关于怎样下载使用PHP和Amazon S3的SDK文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文