skip to Main Content

Here is my code that I have placed in the functions.php file, which doesn’t work:
"Sorry, this file type is not permitted for security reasons." What am I doing wrong?

function zerodropout_mime_types( $mime_types ) {
    $mime_types['xlsm'] = 'application/vnd.ms-excel.sheet.macroEnabled.12';
    return $mime_types;
}
add_filter( 'upload_mimes', 'zerodropout_mime_types', 1, 1 );

2

Answers


  1. WP Upload section is designed for media files. That’s why your code would work for some custom media file type, but not for XLS.
    To enable any kind of file you need to disable default upload type limitation by adding this to your wp-config.php

    define( 'ALLOW_UNFILTERED_UPLOADS', true );
    

    After that your code will work.

    Login or Signup to reply.
  2. This will work:

    function custom_mime_types( $mime_types ) {
        $mime_types['xlsm'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
        return $mime_types;
    }
    add_filter( 'upload_mimes', 'custom_mime_types', 1, 1 );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search