I have created custom code as you mentioned above, and changed form id and field name. I tried to upload 5mb picture and its successfully uploaded instead of giving error. Can you please check once the code and let me know.
<?php
/**
* New custom code snippet (replace this with snippet description).
*/
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
// Put the code of your snippet below this comment.
add_filter('cred_form_validate','func_validate_image_repeating_field_size',10,2);
function func_validate_image_repeating_field_size($error_fields, $form_data) {
list($fields,$errors)=$error_fields;
// target form IDs
$forms = array( 1867 );
if (in_array($form_data['id'], $forms ) ) {
/// target form field
$form_fields = array("wpcf-crew-member-images");
/// allowed size
$number_of_mb_limit = 2;
$max_size = $number_of_mb_limit * (1024 * 1024);
/// allowed number of images
$allowed_count = 2;
foreach($form_fields as $k=>$v):
$count = count($_FILES[$v]['type']);
for($i=0;$i<$count;$i++) {
$size = $_FILES[$v]['size'][$i];
if ( ( $size >= $max_size and $count > $allowed_count) ) {
$errors[$v] = 'Sorry the file you have uploaded exceeded 2MB limit and upload maximum $allowed_count files.';
return array($fields,$errors);
}else if($size >= $max_size){
$errors[$v] = 'Sorry the file you have uploaded exceeded 2MB limit.';
return array($fields,$errors);
}else if($count > $allowed_count){
$errors[$v] = 'You are allowed to upload maximum $allowed_count files.';
return array($fields,$errors);
}
}
endforeach;
}
return array($fields,$errors);
}