note 31188 deleted from features.file-upload by sniper

From: Date: Thu, 29 Jan 2004 07:52:37 +0000
Subject: note 31188 deleted from features.file-upload by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-64351@lists.php.net to get a copy of this message
Note Submitter: timon@fixproject.com ---- 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 ************************************

« previous php.notes (#64351) next »