Selecting multiple files and restricting file types
suggest changeThe HTML5 file API allows you to restrict which kind of files are accepted by simply setting the accept attribute on a file input, e.g.:
<input type="file" accept="image/jpeg">
Specifying multiple MIME types separated by a comma (e.g. image/jpeg,image/png) or using wildcards (e.g. image/* for allowing all types of images) give you a quick and powerful way to restrict the type of files you want to select. Here’s an example for allowing any image or video:
<input type="file" accept="image/*,video/*">
By default, the file input lets the user select a single file. If you want to enable multiple file selection, simply add the multiple attribute:
<input type="file" multiple>
accept is a hint to the file dialog. The page should still check each file. files is a FileList, not an array. See Read file as dataURL.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents