Viewed   294 times

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/ 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.


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?



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!)

Monday, September 19, 2022

So even though the code is all correct the error is actually on PHP itself. There's a spelling mistake in there mime-types. When var_dump($_FILES) it spitting out ["type"]=> string(14) "aplication/pdf" Note that "application" is spelt wrong.

Checked on workmates machine and his correct, so might be an issue with php >5.3.5

Thursday, November 3, 2022

You're correct, uploadify uses the mime type application/octet-stream for most (all?) the files which it uploads. I think this is actually caused by Flash handling the uploading, but I'm not 100% sure.

In your controller where you handle the upload, drop in a print_r($_FILES) and check out what the mime-type is, then just add it to your application/config/mimes.php file.

So in your mimes.php file you'll probably have something like:

'jpg'   =>  array('image/jpeg', 'image/pjpeg', 'application/octet-stream'),
Thursday, November 3, 2022

There's no easy way. You could try:

// return mime type ala mimetype extension
$finfo = finfo_open(FILEINFO_MIME_TYPE);

Of course, this assumes you can install PECL extensions.

Wednesday, October 12, 2022

You'll want the OpenXml SDK for the xlsx:

But for the XLS, you won't be able to use this the XLS format is not based on xml.

I use the NPOI library for accessing older files:

The NPOI library also supports xlsx, so this would give you a consistent way of accessing them. Downside is you'll have to loop through sheets/rows/columns manually, and build up the dataset which will probably affect performance if you have large workbooks. If you want to use queries to access the data, OLEDB is the only method I've found.

Tuesday, December 13, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :