Rheves Posted June 1, 2009 Share Posted June 1, 2009 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"); Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted June 1, 2009 Share Posted June 1, 2009 The code that is generating the XLS is doing it wrong obviously. Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted June 2, 2009 Share Posted June 2, 2009 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.