Skip Navigation

[Résolu] set the minimum resolution of image upload

This support ticket is created Il y a 9 années. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 -
- - - - - - -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 5 réponses, has 3 voix.

Last updated by janO-3 Il y a 8 années et 7 mois.

Assisted by: Waqas.


I am trying to: set the minimum resolution of image upload

I visited this URL: not provided

I expected to see: error message when user upload image less than 300x300pixels

Instead, I got: "user can upload less than 300x300 pixels image"



Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

You can use cred_form_validate filter of CRED API, as below:

add_filter('cred_form_validate_99', 'cred_image_resolution_validation',10,2);
function cred_image_resolution_validation($field_data, $form_data)
    // Field data are field values and errors 
    //Run the rest of code for this CRED ONLY and IF the file is upload type and size are set.
    if (( 99 == $form_data['id']) && (isset($_FILES['wpcf-the-file-field']['tmp_name']))) {
        $check = getimagesize($_FILES["wpcf-the-file-field"]["tmp_name"]);
		if($check !== false) {
			$width = $check[0];
			$height = $check[1];
			if($width < 300 && $height < 300) {
				$errors['the-file-field'] = 'Sorry, too small image.';
		} else {
			$errors['the-file-field'] = 'Sorry this is not a valid image file.';   

    return array($fields,$errors);

Please add this code in your theme's functions.php and adjust accordingly. Specially the "99" should be replaced with your CRED Form's ID, while "wpcf-the-file-field" should be replaced with the actual field name.

You can find more information about CRED API hooks at

And find information about PHP's getimagesize() at hidden link

Please let me know if I can help you with anything related.


Hi, I am busy recently, but I try the code and it is not working.

in my cred form, I use the field below:

<div class="cred-field cred-field-post-featured-image" id="add-post-featured-image-width">
<div class="cred-label">????圖片*</div>
[cred_field field="post-featured-image" post="post" value="" urlparam=""]

so, "wpcf-the-file-field" should be replaced by "post-featured-image" , right?

Then, how about "the-file-field" , should I replace it to sth?



Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

For $_FILES["wpcf-the-file-field"] it should have a prefix of "wpcf-", while for references in CRED and errors array, it is fine without that.

Anyhow, can you please send me temporary access to your site, with URL to your view, cred form and relevant page? So I can check for the issue. Also the functions.php should be writable, to make changes in the relevant filter function.

I have enabled your next reply as Private, please input all information in that area.


Thanks! the code is working!


Thank you for helping answer this application question. One question on this RESOLVED post:

add_filter('cred_form_validate_99', 'cred_image_resolution_validation',10,2);

What is the 10,2 reference? Thanks.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.