![]() |
Identifying uploaded files with mime type application/octet-stream as images - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Identifying uploaded files with mime type application/octet-stream as images (/showthread.php?tid=8874) |
Identifying uploaded files with mime type application/octet-stream as images - El Forum - 06-03-2008 [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 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. Identifying uploaded files with mime type application/octet-stream as images - El Forum - 11-20-2008 [eluser]Chris Newton[/eluser] Tried to add this to a recent script... but Dreamhost doesn't have the Fileinfo extension installed by default. I guess you can compile your own version of PHP, but it's for an internal project and I don't have time to get into all that. Regardless, I saw this months ago, and I still think it's a great idea, and great little extra. Thanks. BTW, in the script above, there's an extra ) at the end of the echo statement. Identifying uploaded files with mime type application/octet-stream as images - El Forum - 05-02-2010 [eluser]Monarobase[/eluser] Hello, I don't know what it's worth security or ressource wise but what about the following approach to get the mime type : Code: function _getmime($file){ This method doesn't need a specific php install and so far has returned the correct mime type on all files I have tested so far, even with the wrong file extension... |