Excel file download corrupted
-
Hi
I am having problem sending excel files to the browser to download. I have created a client file portal plugin to allow clients to download files securely, but have found a problem when they download files. I have recreated the problem here:
Without loading WordPress:
https://www.mccallum-layton.co.uk/downloadtest.phpLoading WordPress:
https://www.mccallum-layton.co.uk/downloadtest-with-wp.phpThe code for both:
Without loading WordPress:$file = "Workbook1.xlsx"; header('Content-disposition: attachment; filename='.$file); header('Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Length: ' . filesize($file)); header('Content-Transfer-Encoding: binary'); header('Cache-Control: must-revalidate'); header('Pragma: public'); ob_clean(); flush(); readfile($file);
Loading WordPress:
$wpload = 'wp-load.php'; require( $wpload ); $file = "Workbook1.xlsx"; header('Content-disposition: attachment; filename='.$file); header('Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Length: ' . filesize($file)); header('Content-Transfer-Encoding: binary'); header('Cache-Control: must-revalidate'); header('Pragma: public'); ob_clean(); flush(); readfile($file);
As you can see, the excel file without loading WordPress works file, but when you load WordPress, the file is corrupted.
Info:
Server: Microsoft-IIS/8.0
PHP/5.4.14Any advice on what the problem is would be greatly appreciated.
Thanks
Jonathan
- The topic ‘Excel file download corrupted’ is closed to new replies.