Add MIME type Validation
-
Hello,
I’m trying to restrict the mime file type upload in the site. but actually, it’s not working. here am attaching the code. kindly please help me to solve the issue.
add_filter('wpcf7_validate_file*', 'cf7_custom_file_validation', 1, 2); add_filter('wpcf7_validate_file', 'cf7_custom_file_validation', 1, 2); function cf7_custom_file_validation ($result, $tag) { if ($tag->name === 'file-234') { $finfo = new finfo(FILEINFO_MIME_TYPE); $contentType = mime_content_type($_FILES[$tag->name]['tmp_name']); if ($contentType !== 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' || $contentType !== 'application/pdf' || $contentType !== 'application/msword') { $result->invalidate($tag, 'This file type is not supported'); } } return $result; }
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Add MIME type Validation’ is closed to new replies.