Jump to content

php created excel file giving different format error


Rheves

Recommended Posts

When I create an excel file in php and try to open it I receive this error: "The file you are trying to open, "EmailUsers.xls", is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?"

 

The data is all there as it should be but I do not want this error showing up. I've included the header code below and have tried changing the content type to application/x-msexcel and application/force-download but that didn't help any.

 

Does anyone know what causes this?

 

	header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=EmailUsers.xls");
header("Pragma: no-cache");
header("Expires: 0");

Fix the content type header, and add in other required headers

header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=EmailUsers.xls");
header ('Content-Transfer-Encoding: binary');
header ('Content-Length: '.filesize('EmailUsers.xls'));
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header ('Cache-Control: cache, must-revalidate');
header ('Pragma: public');

 

How are you creating the Excel file?

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.