Forum Moderators: open

Message Too Old, No Replies

input file html form restrict to jpeg only

         

topr8

12:37 pm on Jul 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



using a straightforward html form, where the user selects a file to upload, am using an: input type=file

is it possible to restrict selection of files to only jpg/jpeg files.

if so how?!

Sanenet

1:00 pm on Jul 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



On the serverside code, check the mimetype of the file to make sure it's a jpg/gif.

Trace

1:08 pm on Jul 14, 2005 (gmt 0)

10+ Year Member



<input type="file" accept="image/jpeg">

I believe that will limit the selection in the drop down menu to only jpg images but I wouldn't trust it.

topr8

1:29 pm on Jul 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



thanx guys.

will validate server side anyway, i wanted to restrict the select user choice as far as possible

tedster

7:25 pm on Jul 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



will validate server side anyway

That's a smart thing to do - especially with jpg files. I believe there still can be some exploits launched from some of the jpg format variants. And obviously any file's extension can always be changed to "say" .jpg

Sanenet

11:18 pm on Jul 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Any file change change it's extension to "jpg" or "gif".

That all that the IE form upload routine checks - the file extension. Check the MIMETYPE for more info on what the file can do.

End of the day, all uploaded files files should be stored in a secured folder to which no read/write access has been given.