Thursday, 24 January 2019

Zlib is breaking CodeIgniter Zip Downloader and PHPExcel

I'm facing an issue where if Zlib compression is enabled on the web server, downloading any zip file using CodeIgniter's force_download function in the system's download_helper.php file breaks the archive file and prevents users from opening it.

enter image description here

Here are the headers being used in the force_download function:

    header('Content-Type: "'.$mime.'"');
    header('Content-Disposition: attachment; filename="'.$filename.'"');
    header("Content-Transfer-Encoding: binary");
    header('Expires: 0');
    header('Pragma: no-cache');
    header("Content-Length: ".strlen($data));

Enabling Zlib also breaks PHPExcel by producing garbled characters in Excel files as you can see in this image.

enter image description here

Headers for PHPExcel download function.

ob_end_clean();                    
header('Content-Description: File Transfer');                            
header('Content-Type: application/vnd.ms-excel');                            
header('Content-Disposition: attachment; filename=' .$fileinfo['filename'] . '_' . $customerId . '_' . date("mdy") . '.xls');              
header('Content-Transfer-Encoding: binary');                            
header('Expires: 0');                            
header('Cache-Control: must-revalidate');                            
header('Pragma: public');                            
header('Content-Length: ' . filesize($file));                            
ob_clean();                            
flush();                            
readfile($file);

Is there a proper workaround to enable Zlib and not breaking these features?



from Zlib is breaking CodeIgniter Zip Downloader and PHPExcel

No comments:

Post a Comment