如何检测浏览器是否支持文件上传? (移动设备和桌面设备)
我正在开发适用于移动和桌面浏览器的应用程序。我想知道是否有办法检测浏览器是否支持文件上传。我正在专门寻找功能检测而不是浏览器检测。有什么办法可以查到吗?
服务器端或客户端都可以。
谢谢
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我正在开发适用于移动和桌面浏览器的应用程序。我想知道是否有办法检测浏览器是否支持文件上传。我正在专门寻找功能检测而不是浏览器检测。有什么办法可以查到吗?
服务器端或客户端都可以。
谢谢
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
客户端 JavaScript:
client side javascript:
您可能有兴趣阅读这篇有关移动设备上当前输入类型=文件支持以及如何检测它的文章:http://viljamis.com/blog/2012/file-upload-support-on-mobile/(该检测目前经过测试,可在约 120 种不同的移动浏览器/移动操作系统组合上运行)。
基本上,我们只是使用与 Modernizr 类似的检测,但使用 UA 检测作为备份来过滤掉那些错误报告支持的移动浏览器(除了使用这两种方法之外,似乎确实没有其他方法可以可靠地检测它,功能检测和浏览器检测)。
You might be interested to read this article about current input type=file support on mobile and how to detect it: http://viljamis.com/blog/2012/file-upload-support-on-mobile/ (the detection is currently tested to be working on ~120 different mobile browser/mobile OS combinations).
Basically, we are just using similar detection as Modernizr does, but use UA detection as a backup to filter out those mobile browsers that falsely report support (there really doesn’t seem to be any other way to detect it reliably than using these both, feature detection and browser detection).
您可以使用带有
forms-fileinput
扩展的 Modernizr 框架。尝试一下。访问 Modernizr 下载页面 并检查
forms-fileinput
扩展(展开“Non -核心检测”部分)。You can use Modernizr framework with
forms-fileinput
extension. Give it a try.Visit the Modernizr download page and check the
forms-fileinput
extension (expand the "Non-core detects" section).Modernizr 现在支持检查是否支持文件上传。
来自:最好的方法是什么检查用户是否可以上传文件?
如果您担心此库的大小,您始终可以一次获取一个组件 - http://modernizr.com/download/ ...或者您可以复制他们使用的代码:https://github.com/Modernizr/Modernizr/blob/master/feature-detects/forms/fileinput.js
Modernizr now supports a check for whether or not file uploads are supported.
From: What is the best way to check if user can upload files?
If you're worried about the size of this library, you can always get one component at a time - http://modernizr.com/download/ ... or you can just copy the code they use: https://github.com/Modernizr/Modernizr/blob/master/feature-detects/forms/fileinput.js