加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 保存并下载PDF

发布时间:2020-12-13 18:23:37 所属栏目:PHP教程 来源:网络整理
导读:我需要一起做两件事.与DOMPDF同时使用. 我需要一起做以下事情 – 这可能吗? //print the pdf file to the screen for saving$dompdf-stream("pdf_filename_".rand(10,1000).".pdf",array("Attachment" = false));//save the pdf file on the serverfile_put
我需要一起做两件事.与DOMPDF同时使用.

我需要一起做以下事情 – 这可能吗?

//print the pdf file to the screen for saving
$dompdf->stream("pdf_filename_".rand(10,1000).".pdf",array("Attachment" => false));
//save the pdf file on the server
file_put_contents('/home/stsnew/public_html/pdf/file.pdf',$dompdf->output());

如果$dompdf-> stream和$dompdf-> output()分别/单独完成,上面的工作正常,但是当我尝试如上所示一起运行它们时,它只会崩溃.

任何帮助/建议将非常感激.

为什么不交换它们首先创建pdf作为文件,然后将创建的文件流回来?
$file_to_save = '/home/stsnew/public_html/pdf/file.pdf';
//save the pdf file on the server
file_put_contents($file_to_save,$dompdf->output()); 
//print the pdf file to the screen for saving
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="file.pdf"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file_to_save));
header('Accept-Ranges: bytes');
readfile($file_to_save);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读