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

Updated:   |  PHP articles

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 products, including Excel, have some issue when cell A1 is ID.

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

 

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

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

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


December 28 2022 by Javed Ur Rehman
Very helpful, thanks bro.

Add a Comment


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