Reputation: 31
sir is it possible to check uploaded image dimension match with this dimensions 250, 468x60, 320x50, 216x36, 168x28, 300x250, 300x50
and if not match error message will like this
Image Size is not valid, available sizes are 300x250, 468x60, 320x50, 216x36, 168x28, 300x250, 300x50
Upvotes: 2
Views: 1264
Reputation: 5092
$file=$uploaddir . basename($_FILES['file']['name']);
if (move_uploaded_file($_FILES['file']['tmp_name'], $file)) {
$size = getimagesize($files);
$maxWidth = 500; // as per your max width requerment
$maxHeight = 250; // as per your max hight requerment
if ($size[0] > $maxWidth || $size[1] > $maxHeight)
{
unlink($file);
rmdir("./uploads/temp/".$user."/".$mx."/".$hash."/");
rmdir("./uploads/temp/".$user."/".$mx."/");
rmdir("./uploads/temp/".$user."/");
}
else
echo $result= "Image Size is not valid, available sizes are 300x250, 468x60, 320x50, 216x36, 168x28, 300x250, 300x50";
end if
} else {
echo $result= "Not valid Image found";
}
Upvotes: 0
Reputation: 924
Check out this code:-
$file = $_FILES["files"]['tmp_name']; // uploaded files
list($width, $height) = getimagesize($file);
$string = $width.'x'.$height;
$predefined_sizes = array('300x250', '468x60', '320x50', '216x36', '168x28', '300x250', '300x50'); // custom image size array
if(!in_array($string,$predefined_sizes)) {
echo "Image Size is not valid, available sizes are 300x250, 468x60, 320x50, 216x36, 168x28, 300x250, 300x50";
// Or you can also do to avoid repetion of sizes.
//echo "Image Size is not valid, available sizes are ".implode(', ',$predefined_sizes);
exit;
}else{
echo 'Valid image';
}
Upvotes: 1