Jump to content

How to restrict file type


AGazzaz

Recommended Posts

HelloI have a form and I want to restrict users choice to images only but the following code is not working. What could be the problem?

<form>  <p align="center"> Photo to upload: <input type="submit" accept="image/*" name="photo" /> </p></form>

Link to comment
Share on other sites

Shouldn't this be set on the file input field itself, i.e.

<form>  <p align="center"> Photo to upload: <input type="file" accept="image/*" name="photo" /> </p>  <input type="submit"/></form>

Link to comment
Share on other sites

Probably better to create a list of acceptable image types to check against in a function using php scripting (or js) rather than use a 'wildcard'
Yeah. Such check should be made anyways, since the request could be forged, so someone may send any file, regardless of what you have specified.In addition, I just tryed that, and it seems Opera is the only browsers that even regards the "accept" attribute to begin with. So, if you want, keep it as I've shown it, but yes, also make a server side check, and on the form, inform the user the file must be an image, whitelisting the actual accepted MIME types (or better yet - the extensions).
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...