SpreadsheetML file extension changed by IE and FF

2019-07-19 16:37发布

I am generating a SpreadsheetML file in PHP. When users download the file and save it, by default the file saves as Report.xml and opens in Excel. However, if the chooses to open the file in Excel instead of saving it, the filename is changed to Report.xml.xls, causing Excel to display an error message. How can I stop the xls extension from being added to the filename?

These are the headers that I am sending:

header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="' . $filename . '.xml"');
header('Cache-Control: max-age=0');
header("Pragma: must-revalidate");

I also tried changing the content-type to text/xml which worked in IE but caused the file to be displayed as raw XML in other browsers.

0条回答
登录 后发表回答