CodeIgniter Forums
image upload, mime check - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19)
+--- Thread: image upload, mime check (/showthread.php?tid=64514)



image upload, mime check - badger - 02-28-2016

While trying to upload a particular png image, i kept getting disallowed file type. I tracked it to a wrong extension (which is not all that unusual and the image shows up ok in the image browser). In upload.php, getimagesize() was reporting the mime type as image/jpeg but in is_allowed_filetype() circa line 914, the mime check is done based on the file extension ie png so it was looking for "image/jpeg" in "[image/png,image/x-png]" and not finding it. Maybe the next issue of codeigniter might include an error message to say in such cases that the file extension is incorrect instead of giving the misleading impression that png files are not allowed.
Bill


RE: image upload, mime check - skunkbad - 02-28-2016

That's odd. I've uploaded all kinds of pictures and documents and never had a problem like this.


RE: image upload, mime check - badger - 02-28-2016

(02-28-2016, 12:39 PM)skunkbad Wrote: That's odd. I've uploaded all kinds of pictures and documents and never had a problem like this.

well, it's a complete fluke that i came across it - murphys law. just happened to pick a png during testing which looked fine in the file manager but refused to upload. for the time being, i'm using
PHP Code:
if (@getimagesize($file['tmp_name']) === FALSE){
            
$this->errorMessage 'getimagesize is false';
        } else {
            
$data['mimetype'] = getimagesize($file['tmp_name'])['mime'];
            
// clog('mimetype: "' . $data['mimetype'] .'", ext: "' .$data['ext'].'"');
            // $data['mimetype'] is eg "image/png", $data['ext'] is eg "png"
            
if ($data['ext']=='jpg'){
                if (
'image/jpeg' != $data['mimetype']){
                    
$this->errorMessage 'wrong image extension: '.$data['ext'].', '.$data['mimetype'];
                    return -
1;
                }
            }
            else
            if (
'image/'.$data['ext'] != $data['mimetype']){
                
$this->errorMessage 'wrong image extension: '.$data['ext'].', '.$data['mimetype'];
                return -
1;
            }
        } 



RE: image upload, mime check - InsiteFX - 02-28-2016

This should be reported to the developers on GitHub


RE: image upload, mime check - Narf - 02-28-2016

(02-28-2016, 04:00 PM)InsiteFX Wrote: This should be reported to the developers on GitHub

Or not.