[eluser]kallus[/eluser]
We had a problem with some devices (playstation portable) setting the mime type to application/octet-stream instead of image/jpeg or image/gif etc. for uploaded image files (hence making the upload library reject the files as non-images). I wrote this code that uses the php extension Fileinfo to read the files magic bytes and replaces the very generic application/octet-stream type with a more specific one. Might be something to add to the CI uploading library. (Downside is that the Fileinfo extension needs to be installed on the server)
Code:
//if mime type is application/octet-stream (psp gives jpegs that type) try to find a more specific mime type
$mimetype = strtolower(preg_replace("/^(.+?);.*$/", "\\1", $_FILES['form_field']['type'])); //reg exp copied from CIs Upload.php
if($mimetype == 'application/octet-stream'){
$finfo = finfo_open(FILEINFO_MIME, '/usr/share/file/magic');
if($finfo){
$_FILES['form_field']['type'] = finfo_file($finfo, $_FILES['form_field']['tmp_name']);
finfo_close($finfo);
}
else echo "finfo_open() returned false");
}
I do this before calling $this->upload->do_upload('form_field'), but it could as well be done in an extension to the uploading library.