$max_image_width = 1600; $max_image_height = 1600; $max_image_size = 4882 * 1024; $min_image_size = 32 * 1024; $valid_types = array("gif","jpg", "png", "jpeg"); if(isset($_FILES['file'])) { if (is_uploaded_file($_FILES['file']['tmp_name'])) { $filename = $_FILES['file']['tmp_name']; $ext = substr($_FILES['file']['name'], 1 + strrpos($_FILES['file']['name'], ".")); if (filesize($filename) < $min_image_size) { echo 'Error: File size < 32K.'; } elseif (filesize($filename) > $max_image_size) { echo 'Error: File size > 5М.'; } elseif (!in_array($ext, $valid_types)) { echo 'Error: Invalid file type.'; } else { $size = GetImageSize($filename); if (($size) && ($size[0] < $max_image_width) && ($size[1] < $max_image_height)) { move_uploaded_file($filename, "img/ava/".$filename); } else { echo 'Error: invalid image properties.'; } } } else { echo "Error: empty file."; } }