Skip Navigation

[Résolu] File Size Limit

This support ticket is created Il y a 7 années et 12 mois. 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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 -
- - - - - - -

Supporter timezone: Europe/Madrid (GMT+01:00)

This topic contains 3 réponses, has 3 voix.

Last updated by kelvinL-2 Il y a 7 années et 11 mois.

Assigned support staff: Caridad.

Auteur
Publications
#268910

Hi, I' ve read this post here https://toolset.com/forums/topic/types-file-custom-field-and-cred/ which sounds idea, however I have 4 different cred form IDs I'd like to use it with - I'm a newbie when it comes to PHP/jQuery etc - so not sure how I would change the example to work with 4 ID's rather than just the one.

Any help would be greatly appreciated.

#268974

There is another way to target a CRED form by id, with a different hook name. Lets say you have forms 20, 21, 22 & 23.

add_filter('cred_form_validate_20','cred_filetype_size_validation',10,2);
add_filter('cred_form_validate_21','cred_filetype_size_validation',10,2);
add_filter('cred_form_validate_22','cred_filetype_size_validation',10,2);
add_filter('cred_form_validate_23','cred_filetype_size_validation',10,2);

function cred_filetype_size_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 (isset($_FILES['wpcf-the-file-field']['type'])) && (isset($_FILES['wpcf-the-file-field']['size'])) {
  
        //Retrieve file type
        $file_type_uploaded=$_FILES['wpcf-the-file-field']['type'];
         
        //Retrieve file size
        $file_size_uploaded=$_FILES['wpcf-the-file-field']['size'];
         
        //Validate files uploaded, make sure its PDF file type AND not more than 100kB
        if (!(  ('application/pdf' == $file_type_uploaded) && ($file_size_uploaded < 100000) )) {
             
            //Validation failed,
            // set error message per field
            //Remove wpcf - prefix here!
            $errors['the-file-field']='Sorry the file you have uploaded is not of correct type or exceeded 100kB limit.';  
                 
        }
  
    }
    //return result
    return array($fields,$errors);
}

Please let me know if you are satisfied with my reply and any other questions you may have.

Regards,
Caridad

#269046

Thanks Caridad, I had to put extra brackets around line 12, but that seems to work well.

I have another couple of questions regarding Cred and Types, but will add them to new posts so people can search them for future reference (I know I've found articles on this forum really helpful).

Thanks

Adam

#275245

Dear Caridad,

For the script $_FILES['wpcf-the-file-field']['type'], what is the 'wpfc-the-file-field' if my field tag is "brcopy"?

Best regards,

Kelvin.