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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.