怎样下载使用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;