I want my uploader only allows these types:
How can I achieve this? What should I put in the accept
attribute? Thanks for your help.
EDIT!!!
I have one more thing to ask. When the popup appears for use to choose file, at the down right corner, there is a drop down list contains all allow files. In my case, the list would be long. I see in the list, there is an option called All Supported Types
. How can I make it chosen by default and eliminate all other options?
Any help will be appreciated. Thank you.
The <input type="file"> defines a file-select field and a "Browse" button for file uploads. To define a file-select field that allows multiple files to be selected, add the multiple attribute. Tip: Always add the <label> tag for best accessibility practices!
Using type="file" and accept="image/*" (or the format you want), allow the user to chose a file with specific format.
call( inputs, function( input ) { var label = input. nextElementSibling, labelVal = label. innerHTML; input. addEventListener( 'change', function( e ) { var fileName = ''; if( this.
The value of the accept
attribute is, as per HTML5 LC, a comma-separated list of items, each of which is a specific media type like image/gif
, or a notation like image/*
that refers to all image
types, or a filename extension like .gif
. IE 10+ and Chrome support all of these, whereas Firefox does not support the extensions. Thus, the safest way is to use media types and notations like image/*
, in this case
<input type="file" name="foo" accept= "application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint, text/plain, application/pdf, image/*">
if I understand the intents correctly. Beware that browsers might not recognize the media type names exactly as specified in the authoritative registry, so some testing is needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With