Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
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 for only images that are in the PNG format. So I'll save that, come back here, I'll refresh the page, and I'll hit the choose file button again and see what happens. Now notice that I can only choose the nameplate.png because it's the only PNG file.
You can also accept all image file types by using a star. So if I hit save, I'm going to come back here, refresh. Hit choose file, and go back. Notice that I can select a car, which is a JPEG, and this nameplate, which is a PNG. Now I can only choose one at a time, but if I add the keyword multiple as an attribute, I can choose more than one file. When I refresh this page, notice that it says choose files. So I'll click on this. And I can now hold down the command key on a Mac or the control on a PC, and select more than one file at time.
You can also choose a list of different types by using commas. So I can say I want to use only audio that is in the MP3 format, as well as any video file. I'll save this, come back here and refresh, and hit the choose file button, and now I can choose this motionpass.mov movie as well as these two audio files. Now if you want to see a comprehensive list of available MIME types, make sure you check out this website. This is the official registry of MIME media types.
So I can't wait for the day when these attributes are standard across all browsers. They offer a lot of functionality for a very small price. However for the time being, you'll probably need to test in whatever browser your site needs to support.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 98235 Viewers
61 Video lessons · 85544 Viewers
71 Video lessons · 69495 Viewers
56 Video lessons · 101838 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.