我可以使用html input元素的accept属性来指定要上传的文件类型吗?
大家好,我想验证在服务器上上传到 .txt 扩展名的文件类型。我可以使用输入元素的接受属性来过滤文件类型吗?如果是的话我该怎么做,如果还有其他方法吗?
一些代码是
<input type="file" name="uploadfile" value="" size="50" />
谢谢
hello everyone i want validate the type of file being uploaded on sever to .txt extension. Can i use accept attribute of input element to filter out the type of file. If yes how can i do that and if any other way ??
Some code is
<input type="file" name="uploadfile" value="" size="50" />
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是javascript自定义验证
,是的,您也可以使用accept属性:
但是据我所知,IE和Safari不支持它,
但请确保也在服务器端验证上传的文件。仅客户验证是不够的。
here is javascript custom validation
And yes you can use accept attribute as well:
However as far as I know it is not supported by IE and Safari
But please make sure to validate the uploaded file on the server side as well. Just client validation is not enough.
你好,在普通的 html 中你不能这样做,
你需要闪存支持。
最好使用uploadify插件
http://www.uploadify.com/
Hi in normal html you can't do that ,
you need flash support for this .
Better use the uploadify plugin
http://www.uploadify.com/
是的,您可以使用
accept
属性。浏览器支持各不相同。它采用 Internet 媒体类型(MIME 类型)列表作为值。对于纯文本(通常是 .txt 文件),则为accept="text/plain"
。通过将选择限制为浏览器视为纯文本文件的文件,这可能会或可能不会影响文件选择功能。Yes, you can use the
accept
attribute. Browser supports varies. It takes an Internet media type (MIME type) list as value. For plain text (which is that .txt files usually are), that would beaccept="text/plain"
. This may or may not affect the file selection functionality by restricting the choices to files that the browser regards as plain text files.