我正在使用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;
}
}
这是我得到的错误:
An uncaught Exception was encountered
Type: ParseError
Message: syntax error, unexpected '='
Filename: /app/third_party/dompdf/src/Dompdf.php
Line Number: 356
如果您使用的是 Dompdf 0.8.5,这是您的异常行
[$this->protocol, $this->baseHost, $this->basePath] = Helpers::explode_url($file);
如果这适用于本地主机,但不适用于实时服务器,则可能是PHP版本的问题,因为此行使用PHP 7.1中引入的新语法