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.
I am using WordPress v5.2 and someone suggested me to try below solution but didn't work either.
function wpse323750_multi_mimes( $check, $file, $filename, $mimes ) {
if ( empty( $check['ext'] ) && empty( $check['type'] ) ) {
$multi_mimes = [ [ 'xls' => 'application/excel' ], [ 'xls' => 'application/vnd.ms-excel' ], ['xls' => 'application/x-excel' ], ['xls' => 'application/x-msexcel'] ];
foreach( $multi_mimes as $mime ) {
remove_filter( 'wp_check_filetype_and_ext', 'wpse323750_multi_mimes', 99, 4 );
$check = wp_check_filetype_and_ext( $file, $filename, $mime );
add_filter( 'wp_check_filetype_and_ext', 'wpse323750_multi_mimes', 99, 4 );
if ( ! empty( $check['ext'] ) || ! empty( $check['type'] ) ) {
return $check;
}
}
}
return $check;
}
add_filter( 'wp_check_filetype_and_ext', 'wpse323750_multi_mimes', 99, 4 );
function.php
", was the file namedfunction.php
orfunctions.php
? That will only work if you insert the code into your active theme'sfunctions.php
file.function.php
would be ignored.