概述
当我想要限制上传的文件格式时
第一种
- csv
<input type="file" accept=".csv" />
- .xls(Excel Files 97-2003)
<input type="file" accept="application/vnd.ms-excel" />
- .xlsx(Excel Files 2007+ )
<input type="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />
- .txt
<input type="file" accept="text/plain" />
- .png/.jpg/etc
<input type="file" accept="image/*" />
- .htm,.html
<input type="file" accept="text/html" />
- .avi, .mpg, .mpeg, .mp4
<input type="file" accept="video/*" />
- .mp3, .wav, etc
<input type="file" accept="audio/*" />
<input type="file" accept=".pdf" />
注意:当你想要能够上传csv时 不要使用以下:
text/csv
application/csv
text/comma-separated-values (works in Opera only).
第二种
<input type="file" ID="fileSelect" accept=".xlsx, .xls, .csv"/>
踩坑:
一些基于upload封装的组件,当我在使用accept的时候,他会报错图片格式问题,具体原因不详。
可以参考:
https://stackoverflow.com/questions/11832930/html-input-file-accept-attribute-file-type-csv
最后
以上就是愉快豌豆为你收集整理的前端上传文件限制指定文件类型 xls、xlsx、csv、image、video等的全部内容,希望文章能够帮你解决前端上传文件限制指定文件类型 xls、xlsx、csv、image、video等所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复