1

I have an old school user who wants to upload an excel file to our Wordpress page.

Basically, Wordpress does not allow this.

Upon

https://gist.github.com/robwent/e3bf00bafe7a00bc3d0c4dceabde4fca

I put the following into functions.php before the end "Includes":

function my_custom_mime_types( $mimes ) {

    // New allowed mime types.
    $mimes['xls'] = 'application/vnd.ms-excel';

    return $mimes;
}
add_filter( 'upload_mimes', 'my_custom_mime_types', 9999 );

But upon uploading an .xls file I get an error message that due to security this is not allowed (re-translated from my native language).

Was this an attempt in the right direction? How can I make this work?

4

I think the proper filter would be mime_types found here.

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

You can use command line tool file (linux|macOS) to see the mime type, e.g. file --mime-type -b somefile.xls

  • 1
    add_filters ruined the theme and nothing appeared on the screen. using add_filter (without ending s) didn't do this, but I still cannot upload xls files, it says for security reasons it does not allow uploading it – Gergely Feb 28 '18 at 13:12
0

I tried the above solution but didn't work for me in the end

I allowed all the mime types via wp-config.php

define( 'ALLOW_UNFILTERED_UPLOADS', true );

You can create your custom restriction when the file is submitted. use $_FILES array and put your restriction on the extension of the file and type before upload.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.