Welcome Guest, Not a member yet? Register   Sign In
image upload, mime check
#1

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
Reply
#2

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

(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;
            }
        } 
Reply
#4

This should be reported to the developers on GitHub
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

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

Or not.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB