Friday, August 14, 2015

Send back a MS Excel file from PHP

Trick source
This 'beautiful' mesh of http headers are needed to get IE downloading the file!!!

header("Pragma: public");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Type: application/vnd.ms-excel");                 //* Decent browsers only need 
header("Content-Disposition: attachment; filename=coupons.xls" ); //* these two headers
header("Content-Transfer-Encoding: binary");      
header("Content-Length: " .  filesize("file.xls") ); 
 
 
readfile("file.xls");

No comments: