1) {
$uploadpath = $uploadpath . basename( $_FILES['fileup']['name']); // gets the file name
$sepext = explode('.', strtolower($_FILES['fileup']['name']));
$type = end($sepext); // gets extension
list($width, $height) = getimagesize($_FILES['fileup']['tmp_name']); // gets image width and height
$err = ''; // to store the errors
// Checks if the file has allowed type, size, width and height (for images)
if(!in_array($type, $allowtype)) $err .= 'The file: '. $_FILES['fileup']['name']. ' not has the allowed extension type.';
if($_FILES['fileup']['size'] > $max_size*1000) $err .= '
Maximum file size must be: '. $max_size. ' KB.';
if(isset($width) && isset($height) && ($width >= $alwidth || $height >= $alheight)) $err .= '
The maximum Width x Height must be: '. $alwidth. ' x '. $alheight;
// If no errors, upload the image, else, output the errors
if($err == '') {
if(move_uploaded_file($_FILES['fileup']['tmp_name'], $uploadpath)) {
echo 'File: '. basename( $_FILES['fileup']['name']). ' successfully uploaded:';
echo '
File type: '. $_FILES['fileup']['type'] .'';
echo '
Size: '. number_format($_FILES['fileup']['size']/1024, 3, '.', '') .' KB';
if(isset($width) && isset($height)) echo '
Image Width x Height: '. $width. ' x '. $height;
echo '
Image address: http://'.$_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER['REQUEST_URI']), '\\/').'/'.$uploadpath.'';
}
else echo 'Unable to upload the file.';
}
else echo $err;
}
?>