×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

HTML5 -> 'input' tag -> 'accept' attribute

HTML5 -> 'input' tag -> 'accept' attribute

HTML5 -> 'input' tag -> 'accept' attribute

(OP)
Hi,

I'm a little confused with this attribute, it doesn't appear to do anything?

OK, in IE it has the drop down pre-filtered, but it doesn't work in FF and both still let you select any file you wish.

It will also still allow you to submit a form with a file that is invalid and not an acceptable file type.

Am I missing something or does this HTML5 attribute simply not work in any browser currently?

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music

RE: HTML5 -> 'input' tag -> 'accept' attribute

The "accept" attribute, basically only serves to filter the file selection dialog box to show only valid formats. But there is nothing stopping the user from selecting an invalid one. This type of validation should always be done server side.

It limits what the dialog shows. But it can easily be overridden.

BTW, it works for me on FF and Chrome on Windows and Ubuntu. And IE on Windows to filter the files.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

RE: HTML5 -> 'input' tag -> 'accept' attribute

(OP)
FF still shows 'all files' as default, but it does have the filter as a drop down selection.

I was hoping to only have to check file type once client side, but it seems the shim I'm using isn't working with the options argument (though I may be passing it incorrectly), and now even those that do handle the HTML 5 attribute, don't actually lock down the file type.

Bit odd as the attribute is called 'accept' not 'filter'.

Oh well, looks like I still need to code client side validation on top of this attribute as well as the usual defensive server side coding.

Thanks for the clarification Phil, appreciated.


"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music

RE: HTML5 -> 'input' tag -> 'accept' attribute

Quote:

I was hoping to only have to check file type once client side

Oooh no, dangerous client side that check is.

But seriously not checking server side, preferably by content type (MIME) allows such things as filename.php.jpg or filename.pl.png to be uploaded which will execute as PHP and Perl scripts respectively.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: HTML5 -> 'input' tag -> 'accept' attribute

(OP)
I think you miss-read what I meant.

I was hoping HTML5 'accept' would prevent invalid files being submitted and then I only need the usual server side checking.

It seems I still need to write stuff client side as well as server side.

I wasn't implying I only wanted to do it once on the client side leaving the web service vulnerable!

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music

RE: HTML5 -> 'input' tag -> 'accept' attribute

There's not much you can do client side with a File input as there is no access to the input itself through JS (not sure if jquery offers anything, doubt it though) for security reasons.

Basically there's no way to know what the user is submitting until it reaches the server.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close