input file控件限制上传文件类型

Fork Me On Github
zodream 编程技术 2018年12月

直接设置文件拓展名

多个用英文逗号隔开

html
 
<input type="file"  accept=".xls,.doc,.txt,.pdf"  />
1

通过文件类型

文件 类型
*.3gpp audio/3gpp
*.ac3 audio/ac3
*.asf allpication/vnd.ms-asf
*.au audio/basic
*.css text/css
*.csv text/csv
*.doc application/msword
*.dot application/msword
*.dtd application/xml-dtd
*.dwg image/vnd.dwg
*.dxf image/vnd.dxf
*.gif image/gif
*.htm text/html
*.html text/html
*.jp2 image/jp2
*.jpe image/jpeg
*.jpeg image/jpeg
*.jpg image/jpeg
*.js text/javascript
*.json application/json
*.mp2 audio/mpeg
*.mp3 audio/mpeg
*.mp4 audio/mp4
*.mpeg video/mpeg
*.mpg video/mpeg
*.mpp application/vnd.ms-project
*.ogg application/ogg
*.pdf application/pdf
*.png image/png
*.pot application/vnd.ms-powerpoint
*.pps application/vnd.ms-powerpoint
*.ppt application/vnd.ms-powerpoint
*.rtf application/rtf
*.svf image/vnd.svf
*.tif image/tiff
*.tiff image/tiff
*.txt text/plain
*.wdb application/vnd.ms-works
*.wps application/vnd.ms-works
*.xhtml application/xhtml+xml
*.xlc application/vnd.ms-excel
*.xlm application/vnd.ms-excel
*.xls application/vnd.ms-excel
*.xlt application/vnd.ms-excel
*.xlw application/vnd.ms-excel
*.xml text/xml
*.zip aplication/zip

当前还有一些多文件的通配符

文件 类型
image/* 匹配所有类型图片
audio/* 匹配所有类型音频
video/* 匹配所有类型视频

注意

这都只是针对普通用户有效的显示,

比如直接修改html代码可以避开

或直接通过其他工具上传也可以避开

或修改文件拓展名也可以避开

后端程序还是需要做其他验证

点击查看全文
0 165 0