MIME types file validation
-
Hello,
How can I declare acceptable file types using MIME types.is there any hook have? I have tried with contact form 7 hooks but it’s not worked. can you please check it we need to solve this issue ASAP.
example:
add_filter('wpcf7_validate_file*', 'cf7_custom_file_validation', 10, 2); add_filter('wpcf7_validate_file', 'cf7_custom_file_validation', 10, 2); function cf7_custom_file_validation ($result, $tag) { if ($tag->name === 'file-123') { $contentType = mime_content_type($_FILES[$tag->name]['tmp_name']); if ($contentType !== 'application/docx' && $contentType !== 'application/pdf' && $contentType !== 'application/doc'&& $contentType !== 'application/rtf') { $result->invalidate($tag, 'This file type is not supported'); } } return $result; }
Thanks
Viewing 13 replies - 1 through 13 (of 13 total)
Viewing 13 replies - 1 through 13 (of 13 total)
- The topic ‘MIME types file validation’ is closed to new replies.