
Anthony C. answered 09/23/19
Tutor
4.8
(6)
Knowledgeable and Experienced Programmer Offering Tech Tutoring
Use the following modification to the file input tag:
<input type="file" accept="comma separated list of acceptable extensions" />
For Example, to allow only png, jpg, or gif image files:
<input type="file" accept=".png,.jpg,.gif" />
Some (older) browsers require MIME types rather than extensions:
Ex: Same as above <input type="file" accept="image/png,image/jpg,image/gif" />
Ex: All video types: <input type="file" accept="video/*" />
For maximum compatibility, combine the two:
<input type="file" accept=".png,.jpg,image/png,image/jpg" />
The results you get depend on the browser you use, but for the most part the last one should be the most compatible.