Forum Moderators: open
Hello, does anyone know how to make file extension regex note: my users upload photo from their harddisk so we need to validate the path
First, since this is in the Javascript forum, I'll guess that you hope to do this with Javascript.
This won't be possible, because you want to read the value of the file input box after they've browsed. This is disallowed by browsers for user security. Imagine if you could, it would lead to information about the user's computer and file structure, and that would be a security issue.
So the only real solution here is to do a regex on the server site, using your server side language. But even that is not a complete solution - what's to stop me from saving my malicious virus (.exe) as .jpg?
The best thing to do is use a graphics interface like GD or ImageMagick that actually reads the uploaded file. Get the image type from the graphic interface, if it's one of your valid types you're good to go. This also releases you from improperly named files (or, in the case of Macintosh, no extensions at all.)
Both Perl and PHP have interfaces to these programs, pretty sure a tweak can be added for Windows-based servers and programming.