Joe*_*nks 2 php pdf amazon-s3 laravel
我正在使用Laravel的存储外观,我可以将pdf上传到S3,我也可以获取()其内容,但我无法将其显示或下载到最终用户作为实际的pdf文件.它看起来像原始数据.这是代码:
$file = Storage::disk($storageLocation)->get($urlToPDF);
header("Content-type: application/pdf");
header("Content-Disposition: attachment; filename='file.pdf'");
echo $file;
Run Code Online (Sandbox Code Playgroud)
如何才能做到这一点?我检查了几篇文章(和SO),但没有一篇文章适合我.
我认为这样的事情将在L5.2中完成:
public function download($path)
{
$fs = Storage::getDriver();
$stream = $fs->readStream($path);
return \Response::stream(function() use($stream) {
fpassthru($stream);
}, 200, [
"Content-Type" => $fs->getMimetype($path),
"Content-Length" => $fs->getSize($path),
"Content-disposition" => "attachment; filename=\"" .basename($path) . "\"",
]);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6454 次 |
| 最近记录: |