Custom Validation to file Field – minimum upload size should be 1024 x 768
-
Hi
I am using contact form 7 plugin with Thegem theme. I have a File upload field. I want my users to upload images of minimum dimension 1024 x 768 or more.
I have also added Multiple file upload using plugin.Here is my code
<label> Upload Designs
[mfile UploadDesigns class:cls_design_upload ] </label><label> Upload Designs test
[file uploadyourdesign class:cls_upload] </label>I tried to add custom validation on both of the fileds by changing the filed name. But It’s not working. Here is my code.
add_filter( ‘wpcf7_validate_file’, ‘custom_file_validation_filter’, 20, 2 );
function custom_file_validation_filter( $result, $tag ) {
//echo “test”;
//die();
$tag = new WPCF7_FormTag( $tag );if ( ‘uploadyourdesign’ == $tag->name ) {
$img=getimagesize($file[‘tmp_name’]);
//echo $img;
//echo “test”;
//exit();
$minimum = array(‘width’ => ‘500’, ‘height’ => ‘500’);
$width= $img[0];
$height =$img[1];if ($width < $minimum[‘width’]) {
$result->invalidate( $tag, “Image dimension are to small. Minimum width is {$minimum[‘width’]}px. Uploaded image width is $width px”);
} elseif ($height < $minimum[‘height’]) {
$result->invalidate( $tag, “Image dimension are to small. Minimum height is {$minimum[‘height’]}px. Uploaded image height is $height px”);
}
}return $result;
}It’s not working, and not even printing and message or any error message.
Please guide me how can I validate the filed.
Waiting for your quick response.
Thanks in advance.
- The topic ‘Custom Validation to file Field – minimum upload size should be 1024 x 768’ is closed to new replies.