phpcodeigniteruploadmime-types

Upload xls or xlsx files with codeigniter, mime-type error


Well, i believe this is not a Codeigniter problem per se as it is more of a mime-type.

I'm trying to upload a file, a xls (or xlsx) file and the mime-type the browser and the php report is application/octet-stream instead of application/excel, application/vnd.ms-excel or application/msexcel for a xls file. Of course codeigniter upload plugin will report an error (invalid file type) as it tries to match the file extension with the mime-type.

The weird(est) thing might be that the same code worked for months and now stopped working with the latest Chrome (16.0.912.77), Firefox (10.0) and IE9.

Has anyone had the same (or similar) problem and care to share the solution?

Thank you very much. PS: I won't provide code as it's not really a code matter, but if necessary i'll upload some snippets.

EDIT

It might be relevant: the error doesn't happen with same browsers on a similar configuration, but with MS Office instead of Libre Office (on my pc). It doesn't happen on a GNU/Linux based + Libre Office system either. SO, could it be Windows playin' hard on the open source suite, or the Libre Office changing the mime-types just for the heck of it?


Solution

  • I'm getting this error also.

    CI is reporting a file type of 'application/zip' which makes sense as the xlsx format is a compressed format (rename it to zip and you can open the contents).

    I have added/replaced the following line to the mime types file (application/config/mimes.php):

    'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet','application/zip'),
    

    and that works (for this browser at least!)