【问题标题】:Downloading a pdf file using GuzzleHttp Stream使用 GuzzleHttp Stream 下载 pdf 文件
【发布时间】:2017-01-16 11:38:52
【问题描述】:

我有一个从文件系统读取的 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());

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

帮助感激!

【问题讨论】:

  • 请解释将文件存储在临时位置是什么意思
  • @NadirLatif 需要将此 pdf 与我保存在磁盘上的其他 mpdf 对象合并。出于这个原因,我必须将文件保存在磁盘上,例如 ex '/usr/local/temp/xxx.pdf'
  • 可以使用php复制功能。它将文件从源复制到目标:php.net/manual/en/function.copy.php

标签: php pdf guzzle


【解决方案1】:

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

<?php

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

readfile ($file);

?>

希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 2020-05-19
    • 1970-01-01
    • 2016-09-12
    • 2017-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多