File input 'accept' attribute - is it useful?

前端 未结 8 1617
独厮守ぢ
独厮守ぢ 2020-11-22 02:30

Implementing a file upload under html is fairly simple, but I just noticed that there is an \'accept\' attribute that can be added to the

8条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 03:09

    It's been a few years, and Chrome at least makes use of this attribute. This attribute is very useful from a usability standpoint as it will filter out the unnecessary files for the user, making their experience smoother. However, the user can still select "all files" from the type (or otherwise bypass the filter), thus you should always validate the file where it is actually used; If you're using it on the server, validate it there before using it. The user can always bypass any client-side scripting.

提交回复
热议问题