PHP - Resolve error "The file format and extension of example.csv don't match"

The following errors may appear when using the PHP fputcsv command:

  • The file format and extension of 'example.csv' don't match. The file could be corrupted to unsafe. Unless you trust its source, don't open it. Do you want to open it anyway?
  • Excel has detected that 'example.csv' is a SYLK file, but cannot load it. Either the file has errors or it is not a SYLK file format. Click OK to try to open the file in a different format.

These errors may appear because the first column in the array is ID. Some Microsoft produces, including Excel, have some issues when cell A1 is ID.

fputcsv($fp, array('ID', 'Column2', 'Column3'));


The easy fix for this is to A1 from upper case ID to lower case id.

fputcsv($fp, array('id', 'Column2', 'Column3'));


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter 48066 in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |