How to allow the upload of newer file types not listed in WordPress

October 28th, 2008 by Dan York

In 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:

wpmu-uploadfiletypes.jpg

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: , ,


Related posts:

  1. Adding (video) podcasting support to a WordPress MU (WPMU) installation
  2. Adding video comments to WPMU using Seesmic’s new plugin
  3. Slides now online for OSCON talk: “Building a Corporate Blog Portal using WordPress MU”
  4. Adding the “Unfiltered MU” plugin to WordPress MU to allow all embeds
  5. Tip: How to modify WordPress MU to allow embed objects (specifically for SlideShare)

Tags: , ,


If you found this post interesting or helpful, please consider either subscribing via RSS, becoming a fan on Facebook, or following us on Twitter.


2 Responses to “How to allow the upload of newer file types not listed in WordPress”

  1. Behind The Blog » Blog Archive » Upgrading to WordPress MU 2.7… step by step Says:

    [...] Modify wp-includes/functions.php to allow other Java file types – on line 2070 of the 2.7 file [...]

  2. Silverlight, Windows Live Writer and WordPress - Erno de Weerd - blog community Says:

    [...] 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 [...]

Leave a Reply

Please note: By submitting a comment you agree to comply with our Comment Policy. We welcome all comments, positive or negative, but do reserve the right to remove all or part of blog comments that do not comply with our policy.

Additionally, the first time you leave a comment on this blog, it will be held for moderation. After that first comment has been approved, future comments will be posted without delay.

Additional comments powered by BackType