
Solid, safe website tools.
Whatever your need, Will Bontrager builds powerful software solutions.
|
(Get Attention Ticker for your web site)
Catching Illegal File Extension *Before* It's UploadedBy Will Bontrager You have a form that lets people upload a file. The files you want to accept are only certain types with extensions ".gif" or ".jpg", for example. Browsers, at least some browsers, let the user upload what they please. Master Form V4 can check that what was uploaded is acceptable. But not all scripts can do that.
It would be nice to have something that checks the file name extension right at the form, before the file is uploaded. That's what this blog post is about, a way to do that. Your form needs two things, a name and an onsubmit attribute. The name might be name="MyForm" for example. The onsubmit attribute must be exactly this: Here is an example form: And here is the JavaScript: Two parts of the JavaScript need to be customized. The directions are in the JavaScript itself. Put the JavaScript in the HEAD or BODY area of your web page, above or below the form. It's location doesn't matter so long as it doesn't interfere with other elements of the page. August 23, 2006 Please note: Articles on this website are presented "as is". However - If you have a question about a CGI script, HTML, CSS, PHP, or JavaScript
Rate this blog post.
No page reload! |
|
|
© 1998-2001 William and Mari Bontrager |
|