note 31188 added to features.file-upload

From: Date: Sat, 12 Apr 2003 15:30:54 +0000
Subject: note 31188 added to features.file-upload
Groups: php.notes 
Request: Send a blank email to php-notes+get-46543@lists.php.net to get a copy of this message
This is my simple image upload script which manages a few things : Renames the image when copying from temp/folder to upload/folder. I Used the user_id($id) which almost every good programmer would use. This way 2 files can never have an name issue (overwrite)..... It checks the image matches the maximum width and height... It checks if the image matches the maximum size rules I think this can be useful for some specified webmasters : // Script ************************************* $imtype=$_FILES["imgfile"]["type"]; $imsize=$_FILES["imgfile"]["size"]; $imname=$_FILES["imgfile"]["name"]; $imtemp=$_FILES['imgfile']['tmp_name']; $immaxsize="50000"; $immaxwidth="700"; $immaxheight="700"; if ($imsize > $immaxsize){ $error_message="You Image is $imsize Bytes the maximum allowed is $immaxsize"; } if (!$error_message){ $imgsize = GetImageSize($imgfile); //== check size 0=width, 1=height if (($imgsize[0] > $immaxwidth) || ($imgsize[1] > $immaxheight)){ $error_message="Your image width and height allowed is $immaxwidth by $immaxheight px. Yours did not match this rule"; } }// end if error_message if (!$error_message){ if ($imtype == "image/x-png"){ $extension=".png"; }elseif ($imtype == "image/pjpeg"){ $extension=".jpg"; }elseif ($imtype == "image/gif"){ $extension=".gif"; }else{ $error_message="Please upload images with the extension .jpg or .jpeg or .gif or .png only"; } }//end if error_message if (!$error_message){ if (is_uploaded_file($imtemp)){ copy($imtemp,"$uploaddir/".$id."$extension"); unlink($imtemp); } else { $error_message="You did not match our Security Settings !"; } }// END IF ERROR MESSAGE IS EMPTY & PICTURE SETTINGS if ($error_message){ require ("$dir[func]/error_check.php"); error_check($error_message); exit; }else{ profile_save_message(); } // End Script ************************************ -- http://www.php.net/manual/en/features.file-upload.php http://master.php.net/manage/user-notes.php?action=edit+31188 http://master.php.net/manage/user-notes.php?action=delete+31188 http://master.php.net/manage/user-notes.php?action=reject+31188

« previous php.notes (#46543) next »