Archive for October, 2008

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

Tuesday, October 28th, 2008

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


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.


Upgrading to WordPress 2.6.2…

Monday, October 13th, 2008

On Friday, I made the jump to bring this site up to WordPress 2.6.2, the latest WPMU release. I pretty much just followed the upgrade steps I’d outlined back in June. For those curious, here was the database backup command I used:

mysqldump wordpress --add-drop-table -u username -ppassword | bzip2 -c > wpmudb-backup-20081010.bz2

Obviously I removed the username and password, and yes, there is a space between “-u” and the username and there is not a space between “-p” and the password. I didn’t research whether that was required… I admittedly followed the steps in one of the WPMU Forum posts I found.

With WordPress 2.6.2, I did need to add the following lines to my wp-config.php file:

define( 'LOGGED_IN_KEY', 'text removed' );
define( 'LOGGED_IN_SALT', 'text removed' );
define( 'AUTH_KEY', 'text removed' );
define( 'SECURE_AUTH_KEY', 'text removed' );
define( 'SECURE_AUTH_SALT', 'text removed' );

Obviously I’m again removing the values specific to our system. These lines were shown to me right at the top of the admin interface after I logged in after the upgrade. I just copied/pasted and then needed to login again.

Thankfully by this point, we’ve made most of our customizations either in the custom theme we use for the site or in specific plugins, so really the only post-upgrade manual tweak I had to do was to modify kses.php to allow “skype” and “sip” protocols in URLs as I had documented earlier. At some point I should probably figure out how to make this a plugin so that it survives upgrades… in the meantime it’s not a big deal provided I remember to do so. (Upgrade checklists are your friend!)

I did the upgrade primarily because I knew I needed to keep the site up-to-date on security issues and fixes, but also because I wanted to try out the WordPress app on the iPhone now that we have made the switch from Blackberries to iPhones. As you can see in this test post, the WordPress app on the iPhone does work. It does, though, seem to have one rather annoying limitation for working with WordPress MU that I mentioned there and will write about in more detail in another post.

Meanwhile, we’re up and running on WPMU 2.6.2…

Technorati Tags: , , ,


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.


Testing from an iphone

Friday, October 10th, 2008

So with our new iPhones I naturally had to try the WordPress app for the iPhone. I don’t know that I will write many posts this way, but it is nice to have the option.

The only technical issue so far is that ALL of our blogs seem to show up in the iPhone app as “Speaking of Standards” instead of their correct names.


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.