PHP - excel file download

Viewed 297

I download files from server but excel or word files are corrupted after download. Pdfs, jpgs etc. are ok.

ob_clean();
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: ").$att->getType();
header("Content-Disposition: attachment; filename=" . basename($att->getName()));  
header("Content-Transfer-Encoding: binary");
header("Content-Description: File Transfer");
readfile($path);

Content type for excel I have - application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

3 Answers

Just Change

header("Content-Type: ").$att->getType();

to

header("Content-Type: ".$att->getType());

You send file with null Content-Type...

For excel and word, try changing

header("Content-Type: ").$att->getType();

to

header("Content-Type: application/octet-stream");

or, for excel

header("Content-Type: application/vnd.ms-excel"); 

or, for word

header("Content-Type: application/msword");

Problem was different... I've just had in my php file new line after ?> Thank Amin and Ken for help

Related