File Uploads Through HTML Forms

Make sure your form is set to use the “POST” method. Make sure that the “enctype” is “multipart/form-data”. Add a field of type “file”. That’s it for your HTML. The rest of the work is done on the host side. And that isn’t really that hard either, but different browsers make it more challenging.

If you use Firefox, the file name is just that – the file name. But if you are lucky enough to use Internet Explorer, the file name is actually the entire path to the flie, not just the name. So if you use something like a regular expression to drop all that path information before the file name itself, IE won’t be able to read the file.

The solution? Use the file name provided from the browser as the “from” filename. Use a regular expression, or whatever you like, to determine the “to” filename. Just make sure you don’t strip off that path information prior to uploading the file or IE will fail with a message that looks something like: “Could not read file”.

Once you take care of that, you should be set.


Posted

in