使用GuzzleHttp Stream下载pdf文件

时间:2017-01-15 22:59:05

标签: php pdf guzzle guzzlehttp

我有一个从文件系统读取的pdf文件,现在我可以使用echo直接显示给用户。这就是我所做的:

$file = $client->open($storage_root);
    header('Content-type: application/pdf');
    header('Content-Disposition: inline; filename="' . 'sample' . '.pdf"');
    header('Cache-Control: private, max-age=0, must-revalidate');
    header('Pragma: public');
    echo ($file->getContents());

但我要求以某种方式将此文件保存在临时位置。关于如何做到这一点的任何想法。

帮助赞赏!!

1 个答案:

答案 0 :(得分:-1)

我假设您已将{PDF格式的内容保存在$file中?在这种情况下,您可以使用:

<?php

header("Content-Description: File Transfer"); 
header("Content-Type: application/octet-stream"); 
header("Content-Disposition: attachment; filename='" . basename($file) . "'"); 

readfile ($file);

?>

希望这有帮助!

相关问题