Php 保存并下载PDF

Php 保存并下载PDF,php,dompdf,Php,Dompdf,我需要一起做两件事&同时使用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_htm

我需要一起做两件事&同时使用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);

回答晚了,但可能会有帮助

设置附件为true或1时

$dompdf->stream("pdf_filename_".rand(10,1000).".pdf", array("Attachment" => true));

如果您只是在寻找下载,则无需使用文件内容(

这是一种很好的做法,因此可以接受您选择的答案…:-)我选择了你的答案。。。抱歉,我不知道;-)快速阅读这些内容