I am trying to: limit a file upload size
I used this script:
//Limit upload file size for repeating image custom field
add_filter('cred_form_validate','story_image_size_validation',10,2);
function story_image_size_validation($field_data, $form_data) {
list($fields,$errors)=$field_data;
$arr = array(17, 4098);
if (in_array($form_data[id], $arr)){
if(isset($fields['wpcf-trade-logo']['file_data']['size'])){
if($fields['wpcf-trade-logo']['file_data']['size']>1000){
$file_size = $fields['wpcf-trade-logo']['file_data']['size'];
print_r('Size exceeded: ' . var_dump($file_size)); die();
$errors['trade-logo']='the image size should not be more than 1000 bytes';
}
}
}
return array($fields,$errors);
}
The function is being called as expected - form id is 17. I've tried various re-workings of the script and cannot dump the file_data
Link to a page where the issue can be seen: will provide URL in site info page is: /edit-trades-profile/
I expected to see: error message for filesize exceeded.
Instead, I got: Image uploaded without error
** Duplicator is banned on my server.
Hi James,
I'm able to see the issue on a clean install, so, there is no need for the duplicator package.
I'm going to report this so that it can be handled by the second tier.
Please keep following this ticket and I will notify you once I get any updates.
Thanks.
Hi James,
Can you try the cred_form_ajax_upload_validate hook: https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_ajax_upload_validate
We upload the images using Ajax, that's why we added this hook tio handle images uploads.
I hoe it hepl you.
Thanks.