我正在使用 codeigniter 框架和 dompdf 生成 pdf 。它在本地主機上工作得很好,但在實時服務器上顯示 500 錯誤。我嘗試過調試,但 error_log 文件中沒有顯示任何錯誤。這是函數generate_pdf的代碼。 public function generate_pdf($content, $name = 'download.pdf', $output_type = null, $footer = null, $margin_bottom = null, $header = null, $margin_top = null, $orientation = 'P'){ $this->load->library('pdf'); $html = ''; if (is_array($content)) { foreach ($content as $page) { $html .= $header?'<header>'.$header.'</header>':''; $html .= '<footer>'.($footer?$footer.'<br><span class="pagenum"></span>' : '<span class="pagenum"></span>').'</footer>'; $html .= '<body><div class="page">'.$page['content'].'</div></body>'; } } else { $html .= $header?'<header>'.$header.'</header>' : ''; $html .= $footer?'<footer>'.$footer.'</footer>' : ''; $html .= $content; } $this->pdf->set_option('isPhpEnabled', true); $this->pdf->set_option('isHtml5ParserEnabled', true); $this->pdf->set_option('isRemoteEnabled', true); $this->pdf->set_option('enable_html5_parser', TRUE); // $this->pdf->set_option("DOMPDF_ENABLE_HTML5PARSER", true); // $this->pdf->loadHtml($html); $html = preg_replace('/>\s+</', '><', $html); // $this->pdf->loadHtml($contents); $this->pdf->loadHtml($html); // $dompdf->load_html($html); $this->pdf->setPaper('A4', ($orientation == 'P' ? 'portrait' : 'landscape')); // $dompdf->set_option('enable_html5_parser', TRUE); $this->pdf->render(); // $this->pdf->stream("dompdf_out.pdf", array("Attachment" => true)); // exit(0); if ($output_type == 'S') { // $output = $dompdf->output(); $output = $this->pdf->output(); write_file('assets/uploads/' . $name, $output); return 'assets/uploads/' . $name; } else { $this->pdf->stream($name); return true; }}
1 回答

HUWWW
TA貢獻1874條經驗 獲得超12個贊
如果您使用的是 Dompdf 0.8.5,這是您的異常行
[$this->protocol, $this->baseHost, $this->basePath] = Helpers::explode_url($file);
如果這適用于本地主機但不適用于實時服務器,這可能是 PHP 版本的問題,因為此行使用 PHP 7.1 中引入的新語法
- 1 回答
- 0 關注
- 129 瀏覽
添加回答
舉報
0/150
提交
取消