2

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 3

2

Just Change

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

to

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

You send file with null Content-Type...

Sign up to request clarification or add additional context in comments.

1 Comment

you are right but I also tried header("Content-Type: application/octet-stream"); or header("Content-Type: application/vnd.ms-excel"); or header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") with same result
1

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");

2 Comments

No, I had that it before but It wasn't working
For png and zip, you should use Content-type: image/png and Content-Type: application/zip respectively but in case of problem (say in your case), please try octet-stream or Content-Type: application/vnd.ms-excel or application/msword (please try my revised answer)
0

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

1 Comment

Nice to know that you have fixed the problem. Have a nice day.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.