From the course: Validating and Processing Forms with JavaScript and PHP
Unlock this course with a free trial
Join today to access over 22,400 courses taught by industry experts.
Limiting uploads by MIME types
From the course: Validating and Processing Forms with JavaScript and PHP
Limiting uploads by MIME types
Some HCMO Five attributes are super useful for file validation. You can tell a browser to accept only certain files by using the accept attribute and passing it some MIME types. So what is a MIME type? MIME stands for Multipurpose Internet Mail Extensions. It started out as a format for allowing email attachments in the SNTP protocol, but it has grown way beyond that and is used heavily all over the web. And MIME specification starts out with a main type like image or video, followed by a sub type like JPG or PNG. The accept attribute normally prevents a browser from choosing files that don't meet our criteria. So let's see how that works. Here's a form that's asking the user to upload a file. So I'm going to hit this choose file button. Here I have a bunch of files with different types. So notice that I can choose any of the types that I want. I'm going to hit cancel, and I'll go into the code for this page, and in the file input type, I'm going to add an except attribute. I'll ask…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.