Search code examples
phpwordpressmime-types

I want to allow .xls file to upload in my WordPress, I have tried lot of things but it is still not working I don't know why


I am getting the following error when trying to upload a xls file.

Sorry, this file type is not permitted for security reasons.

Tried plugin wp-extra file type and there is no option to choose an xls file type.

tried pro mime type plugin, there is an option for Xls to allow and I did it too but still not working and getting the same error.

Also tried to add the following code in a function.php

function my_myme_types($mime_types){
      // New allowed mime types.
$mime_types['xls'] = 'application/vnd.ms-excel';

return $mime_types;
}
add_filter('upload_mimes', 'my_myme_types', 1, 1);

but still showing the same error.

Also tried

function wpse294198_mime_types( $mimes ) {
    $mimes['xls|xlsx'] = 'application/vnd.ms-excel';
    return $mimes;
}
add_filter( 'mime_types', 'wpse294198_mime_types' );

the only solution worked is wp-config ALLOW UNFILTERED UPLOADS. but this is risky if we considered the security reason. I just want to allow xls file not any other file format like Php, js extra.

 define(‘ALLOW_UNFILTERED_UPLOADS’, true)

the problem I face with the above solution that now anyone can upload any type of file from anywhere if there is upload option for him. So I believe this is not a good thing. I need a better solution to my problem.


Solution

  • Ok. Try using that plugin WP Extra File Type again.

    • Check "check only file extensions"
    • Check "skip wordpress check"

    Add custom file types:

    • description: ms excel

    • file extension: .xls

    • mime type: application/vnd.ms-excel

    after that you need to check the .xls extension from that list and it should work.