get_allowed_mime_types

About a week back, I was writing a post on this blog and wanted to attach a shell script using WordPress Download Monitor. However when I tried to attach the script file (.sh extension), it gave me “No File Selected” error after trying to upload the file. Tried again, and the same result. I uploaded a zipped version of the file and that uploaded fine. So I figured, it must be an issue with the mime type/file extension. Found this link which reports the same issue and the solution.

Here’s how you fix this.

1. Log on to your server either through SSH or FTP.

2. Change directory to wp-includes directory in the root of your wordpress installation. For Eg (in my case)

cd ~/humbug.in/wp-includes/

3. Open the functions.php file with your favourite editor.

vi functions.php

4. Search for the get_allowed_mime_types function. At the time of writing, its at line 2275.

5. Go to the bottom of the function (Shift + ] in vim) and add a new entry at the end of all the mime type entries for the desired mime type. At the time of writing, all the openoffice formats are the bottom most entries.

// openoffice formats
 'odt' => 'application/vnd.oasis.opendocument.text',
 'odp' => 'application/vnd.oasis.opendocument.presentation',
 'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
 'odg' => 'application/vnd.oasis.opendocument.graphics',
 'odc' => 'application/vnd.oasis.opendocument.chart',
 'odb' => 'application/vnd.oasis.opendocument.database',
 'odf' => 'application/vnd.oasis.opendocument.formula',

6.  See the sample screenshot below for the new ‘sh’ mime type entry. Check this link for a list of mime types.