Results from getimagesize (width and height) aren't correct in PHP -


i got problem getimagesize(). occurs when upload image but.. sometimes.

the script should check image size avatar (profile-pic). if lower or equals 200px x 200px it's ok.

i'm not done script yet, security things missing. i'm totally confused why happens , why happens.

my script:

//updateavatar if(isset($_files['uploadavatar']) , (isset($_session['user']) or isset($_session['dev']))) {     //upload     $uploaddir = "../img/avatar/";//relative path (we're in php folder [one step img])     $avatarextension = pathinfo($_files['uploadavatar']['name'], pathinfo_extension);//avatar extension (jpg,png,gif)     if($avatarextension == "gif" || $avatarextension == "jpeg" || $avatarextension == "jpg" || $avatarextension == "png") {         $_files['uploadavatar']['name'] = $loginname."_avatar".".".$avatarextension;//build new name (max 4 different avas [png/gif/jpg/jpeg] 1 user)         $uploadfile = $uploaddir.basename($_files['uploadavatar']['name']);//'name' key (index) of array         $uploadfileres = getimagesize($uploadfile);//resolutionarray = 0 => width | 1 => height         if(($uploadfileres[0] <= 200) && ($uploadfile[1] <= 200)) {//250x250              if(move_uploaded_file($_files['uploadavatar']['tmp_name'], $uploadfile)) {                 //uploaded                 $newavatarsql = "update userlogin set avatar = '$uploadfile' id = '$rcsid'";                 mysql_query($newavatarsql);                 $avatar = $uploadfile;             } else {//uploadfailed                 $ucfg_error_msg = "<span title=\"serverside failure\" onclick=\"killerrmsg(this)\" class=\"ucfgerrmsg\">upload failed!</span>";             }          }else {//fileresolution  >(200x200)             $errimagesize =  $uploadfileres[0]." x ".$uploadfileres[1];             $ucfg_error_msg = "<span title=\"your avatar had: $errimagesize\" onclick=\"killerrmsg(this)\" class=\"ucfgerrmsg\">avatar resolution was<br />greater 200x200!</span>";         }     }else {//notsupported extension         $ucfg_error_msg = "<span title=\"supported: *.png | *.jpg | *.gif\" onclick=\"killerrmsg(this)\" class=\"ucfgerrmsg\">file-extension not supported!</span>";     } }else {//notloggedin or no avatar submitted or "fresh script" => no real error // blank js     $ucfg_error_msg = "<span class=\"ucfgerrmsg\"></span>"; } 

you not checking errors in upload, first thing should looking @ when uploading files.

check/test $_files['uploadavatar']['error'] before doing $_files array.

see documentation.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -