How to allow the upload of newer file types not listed in WordPress
October 28th, 2008 by Dan YorkIn putting together his post on the basics of programming with SIP Servlets, my colleague Wei Chen had a simple need: he wanted to include a link to a file containing actual SIP servlet code. The challenge was that the WordPress MU user interface was not letting him upload a file ending in “.sar“, which is the suffix used for SAR files (essentially SIP servlet versions of Java JAR files).
No problem, I thought, I’ll just go to the WPMU Site Admin menu and add “sar” to the list of allowed file types on the “Options” page:
While I was there I added “java”, “jar”, “jsp” and “war”, all of which could be file types we’d like to upload as we do more with Java.
Nope!
Try as he could, Wei was still unable to upload the SAR file. I tried changing his permissions. Still no. He sent me the SAR file. I tried. Nope.
And thus commenced several hours of looking through potential plugins and reading WPMU Forum posts until I finally figured out the problem:
The “Upload File Types” field on the Site Admin Options page only allows you to enter in file types FROM A PREVIOUSLY ESTABLISHED LIST OF ALLOWABLE FILE TYPES.
And of course “sar” and friends were not included in that included list of allowable file types. So it didn’t matter that I included the file extensions in that field in the WPMU web GUI – the underlying software was ignoring extensions that weren’t in its list.
Searching through the various files in my WPMU installation for the text of the error string I found (“grep -R” is your friend!), I finally tracked the issue down to the file “<WPMUHome>wp-includes/functions.php” and the specific function wp_check_filetype within that file. There, as shown below, there is a full list of the various allowed file types. My modification was simply this (my change in red):
‘class|jar|sar|java|war|jsp‘ => ‘application/java’,
After that, the upload worked perfectly fine because “sar” was already in the list of “Upload File Types” in the WPMU Site Admin Options page. Wei was able to upload his SAR file and complete his tutorial blog post. I learned a bit more about how WordPress is put together.
Hopefully this post will help some of you who might run into similar issues. (It’s also, quite frankly, a reminder to myself because, of course, this change will not survive a WPMU upgrade that replaces functions.php so I will need to add this to my checklist of post-upgrade items to check.)
For the sake of completeness, here is the entire function that I modified:
function wp_check_filetype( $filename, $mimes = null ) {
// Accepted MIME types are set here as PCRE unless provided.
$mimes = ( is_array( $mimes ) ) ? $mimes : apply_filters( 'upload_mimes', array(
'jpg|jpeg|jpe' => 'image/jpeg',
'gif' => 'image/gif',
'png' => 'image/png',
'bmp' => 'image/bmp',
'tif|tiff' => 'image/tiff',
'ico' => 'image/x-icon',
'asf|asx|wax|wmv|wmx' => 'video/asf',
'avi' => 'video/avi',
'mov|qt' => 'video/quicktime',
'mpeg|mpg|mpe|mp4' => 'video/mpeg',
'txt|c|cc|h' => 'text/plain',
'rtx' => 'text/richtext',
'css' => 'text/css',
'htm|html' => 'text/html',
'mp3|m4a' => 'audio/mpeg',
'ra|ram' => 'audio/x-realaudio',
'wav' => 'audio/wav',
'ogg' => 'audio/ogg',
'mid|midi' => 'audio/midi',
'wma' => 'audio/wma',
'rtf' => 'application/rtf',
'js' => 'application/javascript',
'pdf' => 'application/pdf',
'doc' => 'application/msword',
'pot|pps|ppt' => 'application/vnd.ms-powerpoint',
'wri' => 'application/vnd.ms-write',
'xla|xls|xlt|xlw' => 'application/vnd.ms-excel',
'mdb' => 'application/vnd.ms-access',
'mpp' => 'application/vnd.ms-project',
'swf' => 'application/x-shockwave-flash',
'class|jar|sar|java|war|jsp' => 'application/java',
'tar' => 'application/x-tar',
'zip' => 'application/zip',
'gz|gzip' => 'application/x-gzip',
'exe' => 'application/x-msdownload',
// 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',
)
);
Technorati Tags: wordpress, wordpressmu, wpmu
Related posts:
- Adding video comments to WPMU using Seesmic’s new plugin
- Tip: How to modify WordPress MU to allow embed objects (specifically for SlideShare)
- Adding space above the Seesmic plugin video comment link
- Upgrading to WordPress 2.6.2…
- Enabling skype: and sip: URLs in WordPress MU 1.5.1
Tags: WordPress, wordpressmu, WPMU
Want to learn how Voxeo can help unlock your communications and deliver
a better customer experience?
Please contact us!
If you found this post interesting or helpful, please consider either
subscribing via RSS, becoming
a fan on Facebook, or
following us on Twitter.
RSS Feed





April 3rd, 2009 at 8:10 pm
[...] Modify wp-includes/functions.php to allow other Java file types – on line 2070 of the 2.7 file [...]
June 21st, 2009 at 12:06 pm
[...] doesn’t like to have xap files uploaded to it by default. So you have to instruct WordPress to accept xap files. While it is not hard to do so, it requires access to the php code of WordPress on your site. Here [...]