设置 html 输入的默认文件类型:file
我可以为 HTML 文件输入设置默认文件类型关联吗?例如,只有 .jpg、.bmp/.png 和 HTML 输入控件?单击“浏览”时,对话框应仅显示所有关联的文件类型,而不是通常出现的所有文件。
Can I set default file types association for HTML file input? E.g. just .jpg,.bmp/.png with the HTML input control? When browse is clicked the dialog should show just show all those associated filetypes not allfiles that usually occurs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
HTML
The
accept
attribute of the HTML<form>
element is meant for that, but this optional attribute is ignored by almost all webbrowsers. The answer is Flash or Java Applet. For both there exist 3rd party file upload plugins. E.g. Uploadify, SWFUpload and JumpLoader. Uploadify has my recommendation.不,这是不可能的。
当用户选择一个文件时,您可以在 javascript 中检查文件类型(扩展名),并据此决定是否发布表单。
但是,由于 javascript 可能会被破坏或关闭,因此您必须检查服务器端是否允许您允许的文件类型,只是为了确定。
No, this is not possible.
One a user selects a file you can check the file type (extension) in javascript and decide on the basis of that whether to post the form or not.
However, since javascript can be subverted or turned off, you will have to check server side for the file types you allow, just to be certain.