HTML: How to limit file upload to be only images?

JacobT picture JacobT · Oct 13, 2009 · Viewed 170.5k times · Source

With HTML, how do I limit what kind of filetypes can be uploaded?

To easy the user experience, I want to limit file uploads to be only images (jpeg, gif, png).

<form method="post" action="..." enctype="multipart/form-data">
<label for="image">Photo</label>
<input name="image" type="file" />
</form>

Answer

Ms2ger picture Ms2ger · Oct 13, 2009

HTML5 says <input type="file" accept="image/*">. Of course, never trust client-side validation: Always check again on the server-side...