input accept
The accept attribute on an <input type="file"> suggests which file types a user should choose. It guides the file picker; it is not a security boundary.
What you will learn
- How
acceptguides file selection - How to write extensions, MIME types, and multiple values
- Why the server must validate uploaded files independently
Basic examples
<input type="file" accept="image/png, image/jpeg">
<input type="file" accept=".pdf,.docx">
<input type="file" accept="image/*">
Separate multiple values with commas. A MIME type such as image/png is precise, an extension such as .pdf names a filename ending, and a wildcard such as image/* allows a broad category.
Guide users without promising security
Browsers may allow users to choose a different file, and file names or MIME types can be falsified. On the server, verify the actual file content, size, and permissions before storing or processing an upload.