This is the process behind uploading an image.
It's a fairly simple process that uses a counter to check for a file extention and then runs a check to validate the file size.
If everything is in order the file is uploaded to ./upload_image/ directory along with a the date prefixed.
<?define ("MAX_SIZE","1024");
function getExtension(){
= strrpos(,".");
if (!) {return "";}
= () ;
$ext = substr($str,$i+1,$l);
return $ext;}
$errors=0;
if(isset($_POST['Submit'])){$image=$_FILES['image']['name'];
if ($image){$filename = stripslashes($_FILES['image']['name']);
$today = date("y-m-d_");$extension = getExtension($filename);
$extension = strtolower($extension);
if (($extension != "jpg")
&& ($extension != "jpeg")
&& ($extension != "png")
&& ($extension != "gif")){echo '<h3>Error</h3><p>Upload atempt is not an image file.</p>';
$errors=1;}
else{$size=filesize($_FILES['image']['tmp_name']);
if ($size > MAX_SIZE*1024){echo '<h3>Error</h3><p>File image size is too big</p>';
$errors=1;}
$image_name=$today . $filename;
$newname="./upload_image/".$image_name;
$copied = copy($_FILES['image']['tmp_name'], $newname
if (!$copied){echo '<h3>Error</h3><p>Upload unsuccessfull.</p>';
$errors=1;}
}
}
}
if(isset($_POST['Submit']) && !$errors){echo "<h3>Success</h3><p>Image uploaded successfully.</p>";}
?>
//Start PHP protocol
//Define maximum size in Kb
//Function to start file extention check
//Variable equals find string
//If variable does not equals find string return blank
//Variable equals string minus first varibale
//Variable equals subtract string from second variable
//Return the extention
//Variable error equals 0
//If submit button pressed
//Variable equals files image and name
//If image equals
//Variable name with no slashes
//Define date
//Varibable equals extension of the file...
//...in a lowercase format
//If file is not jpg...
//...jpeg...
//...png...
//...gif...
//...print message
//Add error to counter
//Otherwise
//Get file size
//If file size is bigger than 1024Kb
//Print message
//Add error to counter
//Set date and filename as image name
//Define upload directory
//If copied and new name
//If not copied
//Print message
//Add error to counter
//Close else
//Close if ($image)
//Close submit
//If submit and no errors
//Print message
//End PHP protocol