
February 23rd, 2013, 10:44 AM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 1
Time spent in forums: 34 m 2 sec
Reputation Power: 0
|
|
|
Image Uploader error problem
Hello:
Below is a image uploader script I am working on. I can't seem to get the error system to work right. When I bench test it with a file that is bigger then the max file size it lets the image through and the error message does not show up. Anybody got any ideas on what I'm doing wrong and how to fix it.
Thanks
Wiz
Code:
<?php
//define a maxim size for the uploaded images in Kb
define ("MAX_SIZE","100");
//checks if the form has been submitted
if(isset($_POST['Submit']))
{
//reads the name of the file the user submitted for uploading
$image=$_FILES['image']['name'];
//get the extension of the file in a lower case format
$extension = getExtension($image);
$extension = strtolower($extension);
}
if(isset($_POST['Submit']) && ($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
{
//print error message
echo '<h1>Unknown file extension!</h1>';
echo '<h1>Copy unsuccessfull!</h1>';
exit;
}
//get the size of the image in bytes
$size=filesize($_FILES['file']['size']);
if(isset($_POST['Submit']) && ($size > MAX_SIZE/1024))
{
echo '<h1>You have exceeded the size limit!</h1>';
echo '<h1>Copy unsuccessfull!</h1>';
exit;
}
//the new name will be containing the full path where will be stored (images folder)
$newname="images/".$image;
//If no errors registred, upload and print the success message
if(isset($_POST['Submit']))
{
copy($_FILES['image']['tmp_name'], $newname);
echo "<h1>File Uploaded Successfully! Try again!</h1>";
}
?>
<!--next comes the form, you must set the enctype to "multipart/frm-data" and use an input type "file" -->
<form name="newad" method="post" enctype="multipart/form-data" action="">
<table>
<tr><td><input type="file" name="image"></td></tr>
<tr><td><input name="Submit" type="submit" value="Upload image">
</td></tr>
</table>
</form>
|