Monday 5 November 2007

Browsing for multiple files in a file upload box

If you've used Flickr, you may well have seen their funky uploading tool that lets you pick multiple files to upload and then shows you the status of each as it uploads.

It's very cool, and you may want to copy it on your site. So, how would you do it?

Well, you can't. At least not with the standard tools of the web - HTML and JavaScript. It's a limitation of the input type="file" HTML control that it only allows you to pick a single file. JavaScript can't help because JavaScript code cannot have access to your file-system. So with any standard web-server language (Java, ASP, ASPX, PHP, etc), the user will always have to pick their files one at a time (even if you can spruce things up slightly by capturing all of the files in a single list once they've been chosen).

Well ... actually you can, but you have to rely on something happening at the user's end.

  • You can force the user to zip up all of the files and upload a single archive (which you can then manipulate and unzip using the standard library functionality of your chosen language).
  • You can use a Java Applet, since Java can access files on your machine if you allow it to. This means that the user will have to install the Java runtimes if they don't have them already. You may also need to look into security-signing your applet.
  • You can use an ActiveX control. This has the severe limitation that it will only work on Windows systems. Also, you'll probably need to security-sign it to stop dire warnings from appearing when users visit your site, and it probably won't work in Firefox.
  • You could use a client application. This gives you lots of control, but breaks the web paradigm slightly and you'll have to think about which platforms you want to code for and support.
  • Ah, so how do Flickr do it? They use Flash. It's very nifty, and you might not even notice that it's a Flash application. Uploading multiple files was added in Flash 8 and seems to work well.
Flash could be expensive, if you don't already have it. There's a third-party control available which uses Flash, but I'm not going to link to it just yet as we're still evaluating whether it's any good and how good the "Free" version is.

Update: 2nd April 2008. We started to look at how this is possible using Flex, and it looks doable using the free version of the tool (if a little painful).
Oh, and we looked at how YouTube does it - they use Java. Interesting.
Meanwhile, Microsoft are pushing Silverlight harder and harder. You can't view some of their webcasts without installing it, and every time you download something you are told you'll get a better experience with it. Perhaps it will reach the tipping point after all?

New College Logo

(Hurrah! Google is finally picking up my site. Right, time to add some content.)

I'm currently making a t-shirt related to my old college (New College, Oxford, England) and wanted to add the New College logo. Legalities aside, I couldn't find a decent copy anywhere. The best I found was a 100 x 120 pixel version on Wikipedia I (I've since found some more examples at a random Varsity shop, but nothing very clear).

So - I made my own! It took me a little while, but once I figured out how useful layers are in Paint.NET, I ended up with something that works quite well (with the help of a Tudor Rose from Wikipedia again!). Tada:

New College Oxford logo