Dears,
I am trying to restrict the upload file type to be only ( PDF, JPG ,PNG,JPEG), I am using the below code, but it prevents to upload any type except .pdf . What is the wrong
-------------------------------------------------------------------------------------------------------
<?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','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 (( 5245 == $form_data['id']) && (isset($_FILES['wpcf-card']['type'])) && (isset($_FILES['wpcf-card']['size']))) {
if ( (5245 == $form_data['id']) && (!empty($_POST['wpcf-card'])) ) {
//Retrieve file type
$file_type_uploaded=$_FILES['wpcf-card']['type'];
//Retrieve file size
$file_size_uploaded=$_FILES['wpcf-card']['size'];
//Validate files uploaded, make sure its PDF file type AND not more than 5000kB
if (!( ('application/jpg' == $file_type_uploaded) || ('application/pdf' == $file_type_uploaded) || ('application/png' == $file_type_uploaded) || ('application/jpeg' == $file_type_uploaded) && ($file_size_uploaded < 2097152) )) {
$errors['card']='Sorry the file you have uploaded is not of the correct type or exceeded 2M limit.';
}
}
//return result
return array($fields,$errors);
}