Guest User

Untitled

a guest
Jul 10th, 2021
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.10 KB | None | 0 0
  1. // For the resource file upload - check that the file is a PDF under 1MB in size.
  2. add_filter('cred_form_ajax_upload_validate','cred_filetype_size_validation',10,2);
  3. function cred_filetype_size_validation($error_fields, $form_data)
  4. {
  5.     //field data are field values and errors
  6.     list($fields,$errors)=$error_fields;
  7.     //validate if specific form
  8.     if ( ($form_data['id']==358) || ($form_data['id']==473) )
  9.     {
  10.         if(isset($fields['wpcf-images'])) {
  11.           //Retrieve file type
  12.           $file_type_uploaded=$fields['wpcf-images']['field_data']['type'];
  13.            
  14.           //Retrieve file size
  15.           $file_size_uploaded=$fields['wpcf-images']['field_data']['size'];
  16.            
  17.           //check if featured image exists
  18.           if ( ($file_size_uploaded > 1000000) || ($file_type_uploaded != 'png') )
  19.           {
  20.             //set error message for featured image
  21.             $errors['Resource File'] = 'Sorry the file you have uploaded is not of correct type (png) or exceeded 1MB limit';
  22.           }
  23.         }
  24.     }
  25.     //return result
  26.     return array($fields,$errors);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment