【发布时间】:2015-03-11 04:55:06
【问题描述】:
我有以下代码成功地将 S3 上保存的文件显示到浏览器,但我希望能够将文件下载到客户端的计算机。
我需要做什么?
$result = S3::getObject($Bucketname,$uri);
header("Content-Type: ".$result->headers['type']);
die($result->body);
我尝试了以下方法,但它只是下载了一个无法读取的文件...
$result = S3::getObject($Bucketname,$uri);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=test.pdf');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . strlen($result->body));
ob_clean();
flush();
readfile($result->body);
exit;
【问题讨论】:
标签: php amazon-web-services amazon-s3 download