Jump to content

Problem with downloading Excel file from server - header problem


abdfahim

Recommended Posts

I have an excel file with multiple worksheet in server. When I try to download that file using header function, it download an excel file with garbage text on a sheet. The code I used is

 

$savepath="C://program files/apache/htdocs/myexcelfile.xls";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/vnd.msexcel");
header( "Content-Disposition: attachment; filename=".basename($savepath));
header( "Content-Description: File Transfer");
header('Accept-Ranges: bytes');
header('Content-Length: ' . filesize($savepath));
readfile($savepath);

 

What wrong did I write?

here's a list of all mime headers for excel files, hopefully one will work for you:

application/msexcel
application/x-msexcel
application/x-ms-excel
application/vnd.ms-excel
application/x-excel
application/x-dos_ms_excel
application/xls
application/x-xls
zz-application/zz-winassoc-xls

Oh, and I didn't see anything wrong with your usage of the mime, so that's why I posted the list. If one fails.....

I use all of ur listed mimes with no success :(. Every time it download the file but inside the file all are garbages. Also my original doc in the server has 8 sheets whereas the downloaded one has only one sheet with all garbages !!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.