Ali Zia Ali Zia -3 years ago 107
PHP Question

using dompdf in codeigniter not making pdfs on live

I am creating pdfs using this code

$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$pdf = $dompdf->output();
file_put_contents($this->config->item('file_path') . $pdf_name, $pdf);
$data['pdf'] = site_url('uploads/pdf/' . $pdf_name);


It works perfectly on XMPP localhost, but on LIVE server I get this error.

A PHP Error was encountered

<p>Severity: Warning</p>
<p>Message: file_put_contents(/home/xyz/public_html/abc/uploads/pdf/quotation_1502863603.pdf): failed to open stream: No such file or directory</p>
<p>Filename: controllers/Admin.php</p>
<p>Line Number: 742</p>


Please guide me what could be the issue on a LIVE server?

Answer Source

Wrong in here $this->config->item('file_path') (path - /home/xyz/public_html/abc/uploads/pdf/). This path belongs to localhost and not to the server.

You should have try

$pdf_path = 'uploads/pdf/'.$pdf_name;
file_put_contents($pdf_path, $pdf);

Codeigniter Environment nothing to do with hosting path, its need an only relative path. As well check permeation on upload path (777)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download