On wordpress, how do i require specific dimensions from user uploads only

I have this filter but it is for minimum upload requirements. I need one for sepcific

add_filter('wp_handle_upload_prefilter','tc_handle_upload_prefilter');
function tc_handle_upload_prefilter($file)
{


$img=getimagesize($file['tmp_name']);
$minimum = array('width' => '640', 'height' => '480');
$width= $img[0];
$height =$img[1];

if ($width < $minimum['width'] )
    return array("error"=>"Image dimensions are too small. Minimum width is {$minimum['width']}px. Uploaded image width is $width px");

elseif ($height <  $minimum['height'])
    return array("error"=>"Image dimensions are too small. Minimum height is {$minimum['height']}px. Uploaded image height is $height px");
else
return $file; 


}

Thanks for the help!

Solutions

Compare the exact sizes you want with an inequivalence operator instead of a less than. In other words, change your < to !=

Similar questions

Save uploads directly in the uploads folder (on a multisite)
on my current page I want my uploads to be saved directly in the uploaded folder. So their links should be something like https://example.com/wp-content/uploads/myimage.jpg instead of https://example.com/wp-content/uploads/sites/3/2018/09/myimage.jpg. I remember reading somewhere, that this can be set under Settings->Media. However, the option does...
Uploads going to the root of wp-content/uploads
I have an on-again, off-again client that I just did a Wordpress/plugins/theme update for. When I opened the uploads folder, I noticed that there is one year folder from 2014 and then all the images are at the root level of the uploads folder. I have checked the following for code that would control the upload. I have not found anything that would ...
load/require specific php files for specific pages/templates/post types
I have a plugin with multiple php files. I want to load some of them only when specific template files are loaded. I don't want to load everything. Currently, I'm doing it with add_action( 'wp', 'load_files' ) , but it means actions defined in the additional php files are not being done. Any ideas? EDIT: Seems like there is some of work around, by ...
How to require specific PHP files for specific templates
How can I require specific PHP files for specific templates without any hook? Example: I've one PHP file "autocomplete.php' and once a page template "photographers.php' Now I want to require 'autocomplete.php' file in functions.php file only for photographers.php template. How can I do this? I've tried using is_page_template () but didn't success. ...
Require user to be logged in not working for gravity form though user is logged in wordpress
In a WordPress project, I am using login in frontend. I have included plugin Gravity form. One of the page(e.g. abc) has form with form setting as 'Require user to be logged in'. Issue: When I first log in and go to page abc, form shows(as user is logged in) but when I first go to page abc and then do login although user is logged in form isn't sho...
HTTP Error when uploading images over specific dimensions
Hello I have a reseller account with one wp 3.5 multisite on a shared hosting. Suddenly I can't upload photos after some random dimensions(It uploads the small sized ones just fine, but it has problems with the bigger ones).Specific any photo over than 511(width) i got http error , and any image less than 511(width) upload without any http error Op...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.