简体   繁体   English

DOMPDF 无法在 codeigniter 中的实时服务器上运行

[英]DOMPDF not working on live server in codeigniter

I'm using codeigniter framework and dompdf to generate pdf.我正在使用 codeigniter 框架和 dompdf 来生成 pdf。 It works totally fine on localhost but shows 500 error when on live server.它在本地主机上运行良好,但在实时服务器上显示 500 错误。 I've tried debugging but it doesnt shows any errors in error_log file.我试过调试,但它没有在 error_log 文件中显示任何错误。 Here is the code of the function generate_pdf.这里是 function 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;
    }
}

This is the error which i get:这是我得到的错误:

An uncaught Exception was encountered
Type: ParseError

Message: syntax error, unexpected '='

Filename: /app/third_party/dompdf/src/Dompdf.php

Line Number: 356

If you are using Dompdf 0.8.5, This is your Exception's line如果您使用的是 Dompdf 0.8.5,这是您的异常行

[$this->protocol, $this->baseHost, $this->basePath] = Helpers::explode_url($file);

If this works on localhost but not on live server, this is probably a problem with PHP version since this line uses a new syntax introduced in PHP 7.1如果这适用于 localhost 但不适用于实时服务器,这可能是 PHP 版本的问题,因为该行使用 PHP 7.1 中引入的新语法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM