Using upload_mimes to allow upload and download of unrecognized mime type

Some mime types are not listed with WordPress by default. For example .apk. So when you try to upload or download a file with unknown file type, sometimes it may not work properly, like problem with opening file after download. So in such cases you need to take some additional actions to make it work. WordPress has a filter hook “upload_mimes” and this filter can be used to alter the list of acceptable file extensions ( introducing new file type or excluding any known file type ) WordPress checks during media uploads or sending mime-type / content type header to browser before staring download

Example Usage

To make use of this filter, you will need to place a function similar to the below in your theme’s functions.php file.

Firstly, add the following line of code to your theme’s functions.php file to show WordPress that you want to hook in to this filter:

<?php add_filter('upload_mimes', 'wpdm_custom_mimes'); ?>

The first parameter is the filter name, the second parameter is the name of the function that you are going to create to alter the list (so you can name this as you like, so long as it matches the name in this next piece of code.)

Now for the real work – your function. This adds or removes the file types:

function wpdm_custom_mimes ( $existing_mimes = array() ) 
     // Add file extension 'apk' with mime type 'application/' 
     $existing_mimes['apk'] = 'application/'; 
     return $existing_mimes; 

and now you will be able to upload/download .apk without any trouble.

Comments [ 3 ]

  • Malcolm Beyer

    I know this is an old article, but it’s relevant to me right now. I followed the steps and am still unable to download an .apk file. Anything new since this was posted I should be trying?

  • Malcolm Beyer

    Do I need to add anything to the /wp_includes/functions.php file as well?

Leave a Reply