• 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)
  • Thread Starter navasahmed

    (@navasahmed)

    any update on the above query? please give me an update

    Thread Starter navasahmed

    (@navasahmed)

    am stuck on this issue. kindly please help me to find out the solution.
    mime_content_type($_FILES[$tag->name]['tmp_name']); is giving bool(false) response.

    Thanks

    Thread Starter navasahmed

    (@navasahmed)

    Any update on the above request? it’s very urgent.

    Thanks

    Thread Starter navasahmed

    (@navasahmed)

    Hello,

    Any updates on the above query? the issue is still on the site. we can upload renamed files. here I will breaf down my question.

    if game.exe is renamed as game.pdf and uploaded then it needs to be blocked. currently, it’s not blocking.

    can you please check the issue and we need to solve that ASAP.

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add MIME type Validation’ is closed to new replies.