
//This is the part where we edit our configuration
// Where you want the files to upload to
//Important: Make sure this folders permissions is 0777!
$upload_dir = "uploads";
// If you want to restrict to certain extensions do it here
$extensions_allowed = "jpg, gif, png, pdf";
// This is a maximum limit of 100kb
$max_size = "100000";
// 100 pixels maximum in height, this can be left empty if you don't deal with images
$max_height = "100";
// The same as the above. This refers to the width of the image.
//Leave it empty if you don't deal with images
$max_width = "100";
// We will check the extension here to see if it's allowed or not
$extension = pathinfo($_FILES['file']['name']);
$extension = $extension[extension];
$allowed_paths = explode(", ", $extensions_allowed);
for($i = 0; $i < count($allowed_paths); $i++) {
if ($allowed_paths[$i] == "$extension") {
$ok = "1";
}
}
// We will check the file size here to see if it's within our limits
if ($ok == "1") {
if($_FILES['file']['size'] > $max_size)
{
print "File size is too big!";
exit;
}
// We will check the height and width of the image to see if it's within our limits
if ($max_width && $max_height) {
list($width, $height, $type, $w) = getimagesize($_FILES['file']['tmp_name']);
if($width > $max_width || $height > $max_height)
{
print "File height and/or width are too big!";
exit;
}
}
// If everything passes we upload the file
if(is_uploaded_file($_FILES['file']['tmp_name']))
{
move_uploaded_file($_FILES['file']['tmp_name'],$upload_dir.'/'.$_FILES['file']['name']);
}
print "Your file has been uploaded successfully! Yay!";
} else {
print "Incorrect file extension!";
}
Added by roScripts on April-18-2007, 3:53 pm
