PDF不使用php存储在文件夹内

时间:2015-04-13 05:15:27

标签: php html dompdf

我试图将我的pdf文件存储在数据库中的文件夹中。但它只适用于MAMP服务器。我的代码如下:

$dompdf->load_html($html);
$dompdf->set_paper("A4", "landscape");
$dompdf->render();

 $dompdf->stream($projectdetail->project_name." - Cost Report.pdf", array("Attachment" => false));
 $canvas = $dompdf->get_canvas();
 $font = Font_Metrics::get_font("helvetica", "bold");
 $canvas->page_text(750, 570, "Page: {PAGE_NUM} of {PAGE_COUNT}", $font, 6, array(0,0,0));
 $canvas->page_text(25, 570, "II International P Ltd", $font, 6, array(0,0,0));
 $output = $dompdf->output();
 $file_to_save = '../files/'.$projectdetail->project_name.'/'.$projectdetail->project_name.'.pdf';
 file_put_contents($file_to_save, $output);

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

在代码的早期,您致电$dompdf->stream()。此方法流式传输PDF并停止执行脚本。我不确定为什么它在MAMP而不是其他服务器,但如果你重新安排你的脚本,你应该有更多的运气。

$dompdf->load_html($html);
$dompdf->set_paper("A4", "landscape");
$dompdf->render();

$canvas = $dompdf->get_canvas();
$font = Font_Metrics::get_font("helvetica", "bold");
$canvas->page_text(750, 570, "Page: {PAGE_NUM} of {PAGE_COUNT}", $font, 6, array(0,0,0));
$canvas->page_text(25, 570, "II International P Ltd", $font, 6, array(0,0,0));
$output = $dompdf->output();

$file_to_save = '../files/'.$projectdetail->project_name.'/'.$projectdetail->project_name.'.pdf';
file_put_contents($file_to_save, $output);

$dompdf->stream($projectdetail->project_name." - Cost Report.pdf", array("Attachment" => false));