Skip to content
Advertisement

PHP force_download is downloading file with filename specified but calling it ‘file.pdf’

I am using force_download and everything works well except for the file being named ‘file.pdf’ and not ‘Daily_delivery_sheet.pdf’. The pdf looks correct, it’s just the filename that is wrong. I am stumped as to why this is happening.

In the next function in the same file, the code is exactly the same and it is working perfectly.

Here is my code:

$pdf = $mcccpdf->getPdf($data);
$this->load->helper('download');
$filename = 'Daily_delivery_sheet.pdf';
force_download($filename, $pdf);
exit;

Advertisement

Answer

It turns out that another programmer put $pdfobj->ezStream( array('compress' => 0 ) ); where the PDF was being generated and that was the cause of the problem. I removed it and everything works perfectly now.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement