1

In my PHP application I use phpexcel to dynamically create MS Excel file.

On some of my PC-s, I have a problem because Windows overwrite extenstion of generated XLS file, and it changes it to XLSX.

Can you help me how can I "force", that file extenstion be XLS and not XLSX?

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="'. date('Y-m-d') .'.xls"');
header('Cache-Control: max-age=0');
$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
$objWriter->save('php://output');

I guess that reasion is that some of the browsers have setup that "save file without any questions", and due to that windows change it's extenstion.

so, how can I avoid it, and to save file always and only with XLS extension.

Cœur
  • 37,241
  • 25
  • 195
  • 267
user198003
  • 11,029
  • 28
  • 94
  • 152

2 Answers2

2

Try changing the MIME type to application/vnd.ms-excel (as shown here).

I don't really know but apparently your MIME type is kinda wrong as it's the one for the new xml based office formats whose file extension ends with an "x". So this might be the reason why some behind-the-scene magic renames your file.

Community
  • 1
  • 1
jek
  • 2,406
  • 1
  • 18
  • 27
1

here is a something,

http://www.givegoodweb.com/post/30/forcing-a-download-with-apache-and-htaccess

hope it helps

<Files *.xls>
  ForceType application/octet-stream
  Header set Content-Disposition attachment
</Files>
<Files *.eps>
  ForceType application/octet-stream
  Header set Content-Disposition attachment
</Files>
Val
  • 17,336
  • 23
  • 95
  • 144
  • Apparently this solution works, but is not really correct. It overwrites the content type set by the php script to something which also avoids the renaming, but still does not represent the correct type for this kind of document. Be aware that you'll lose the chance to change the content type for all files ending with the extensions .xls and .eps with a script as apache will always overwrite your headers. So I think this is a quick and very dirty solution. – jek Nov 07 '11 at 13:30