[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.
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
list($fields,$errors)=$field_data;
//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.
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.