I want my uploader only allows these types:
我希望我的上传者只允许这些类型:
- doc, docx.
- 医生,多克斯。
- xls, xlsx.
- xls,xlsx。
- ppt, pptx.
- ppt,pptx。
- txt.
- 三种。
- pdf.
- pdf。
- Image types.
- 图像类型。
How can I achieve this? What should I put in the accept
attribute? Thanks for your help.
我如何做到这一点?我应该在accept属性中放入什么?谢谢你的帮助。
EDIT!!!
编辑! ! !
I have one more thing to ask. When the popup appears for use to choose file, at the down right corner, there is a drop down list contains all allow files. In my case, the list would be long. I see in the list, there is an option called All Supported Types
. How can I make it chosen by default and eliminate all other options?
我还有一件事要问。当弹出窗口用于选择文件时,在右下角,有一个下拉列表包含所有允许的文件。在我的情况下,这个列表会很长。我在列表中看到,有一个选项叫做“所有支持类型”。如何在默认情况下选择它并消除所有其他选项?
Any help will be appreciated. Thank you.
如有任何帮助,我们将不胜感激。谢谢你!
7 个解决方案
#1
59
The value of the accept
attribute is, as per HTML5 LC, a comma-separated list of items, each of which is a specific media type like image/gif
, or a notation like image/*
that refers to all image
types, or a filename extension like .gif
. IE 10+ and Chrome support all of these, whereas Firefox does not support the extensions. Thus, the safest way is to use media types and notations like image/*
, in this case
accept属性的值,如HTML5 LC所示,是一个用逗号分隔的项目列表,每个项目都是特定的媒体类型,比如image/gif,或者是一个符号,比如image/*,表示所有的图像类型,或者是一个文件名扩展名,比如.gif。IE 10+和Chrome支持所有这些,而Firefox不支持扩展。因此,在这种情况下,最安全的方法是使用媒体类型和符号,如image/*
<input type="file" name="foo" accept=
"application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint,
text/plain, application/pdf, image/*">
if I understand the intents correctly. Beware that browsers might not recognize the media type names exactly as specified in the authoritative registry, so some testing is needed.
如果我理解正确的话。请注意,浏览器可能无法完全识别权威注册表中指定的媒体类型名称,因此需要进行一些测试。
#2
37
Use Like below
用下面的
<input type="file" accept=".xlsx,.xls,image/*,.doc, .docx,.ppt, .pptx,.txt,.pdf" />
#3
10
Use accept attribute with the MIME_type as values
使用带有MIME_type的accept属性作为值
<input type="file" accept="image/gif, image/jpeg" />
#4
6
for powerpoint and pdf files:
投影片及pdf档案:
<html>
<input type="file" placeholder="Do you have a .ppt?" name="pptfile" id="pptfile" accept="application/pdf,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.slideshow,application/vnd.openxmlformats-officedocument.presentationml.presentation"/>
</html>
#5
3
IMPORTANT UPDATE:
重要更新:
Due to use of only application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint... allows only till 2003 MS products, and not newest. I've found this:
由于只使用应用/msword、application/vnd。ms excel、应用程序/ vnd.ms-powerpoint……只允许到2003年的MS产品,不是最新的。我发现这个:
application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.ms-powerpoint, application/vnd.openxmlformats-officedocument.presentationml.slideshow, application/vnd.openxmlformats-officedocument.presentationml.presentation
And that includes the new ones. For other files, you can retrieve the MIME TYPE in your file by this way (pardon the lang)(in MIME list types, there aren't this ones):
包括新的。对于其他文件,您可以通过这种方式检索文件中的MIME类型(请原谅lang)(在MIME列表类型中,没有这种类型):
You can select & copy the type of content
您可以选择和复制内容的类型
#6
2
在w3schools是这样陈述的:
audio/* - All sound files are accepted
音频/* -所有声音文件都被接受
video/* - All video files are accepted
视频/* -所有视频文件均可接受
image/* - All image files are accepted
图像/* -所有图像文件都被接受
MIME_type - A valid MIME type, with no parameters. Look at IANA MIME types for a complete list of standard MIME types
MIME_type——有效的MIME类型,没有参数。查看IANA MIME类型,以获得标准MIME类型的完整列表。
#7
0
for image write this
图像写这
<input type=file accept="image/*">
For other, You can use the accept attribute on your form to suggest to the browser to restrict certain types. However, you'll want to re-validate in your server-side code to make sure. Never trust what the client sends you
另一方面,您可以使用表单上的accept属性来建议浏览器限制某些类型。但是,您需要在服务器端代码中重新验证以确保。永远不要相信客户给你的信息
#1
59
The value of the accept
attribute is, as per HTML5 LC, a comma-separated list of items, each of which is a specific media type like image/gif
, or a notation like image/*
that refers to all image
types, or a filename extension like .gif
. IE 10+ and Chrome support all of these, whereas Firefox does not support the extensions. Thus, the safest way is to use media types and notations like image/*
, in this case
accept属性的值,如HTML5 LC所示,是一个用逗号分隔的项目列表,每个项目都是特定的媒体类型,比如image/gif,或者是一个符号,比如image/*,表示所有的图像类型,或者是一个文件名扩展名,比如.gif。IE 10+和Chrome支持所有这些,而Firefox不支持扩展。因此,在这种情况下,最安全的方法是使用媒体类型和符号,如image/*
<input type="file" name="foo" accept=
"application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint,
text/plain, application/pdf, image/*">
if I understand the intents correctly. Beware that browsers might not recognize the media type names exactly as specified in the authoritative registry, so some testing is needed.
如果我理解正确的话。请注意,浏览器可能无法完全识别权威注册表中指定的媒体类型名称,因此需要进行一些测试。
#2
37
Use Like below
用下面的
<input type="file" accept=".xlsx,.xls,image/*,.doc, .docx,.ppt, .pptx,.txt,.pdf" />
#3
10
Use accept attribute with the MIME_type as values
使用带有MIME_type的accept属性作为值
<input type="file" accept="image/gif, image/jpeg" />
#4
6
for powerpoint and pdf files:
投影片及pdf档案:
<html>
<input type="file" placeholder="Do you have a .ppt?" name="pptfile" id="pptfile" accept="application/pdf,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.slideshow,application/vnd.openxmlformats-officedocument.presentationml.presentation"/>
</html>
#5
3
IMPORTANT UPDATE:
重要更新:
Due to use of only application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint... allows only till 2003 MS products, and not newest. I've found this:
由于只使用应用/msword、application/vnd。ms excel、应用程序/ vnd.ms-powerpoint……只允许到2003年的MS产品,不是最新的。我发现这个:
application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.ms-powerpoint, application/vnd.openxmlformats-officedocument.presentationml.slideshow, application/vnd.openxmlformats-officedocument.presentationml.presentation
And that includes the new ones. For other files, you can retrieve the MIME TYPE in your file by this way (pardon the lang)(in MIME list types, there aren't this ones):
包括新的。对于其他文件,您可以通过这种方式检索文件中的MIME类型(请原谅lang)(在MIME列表类型中,没有这种类型):
You can select & copy the type of content
您可以选择和复制内容的类型
#6
2
在w3schools是这样陈述的:
audio/* - All sound files are accepted
音频/* -所有声音文件都被接受
video/* - All video files are accepted
视频/* -所有视频文件均可接受
image/* - All image files are accepted
图像/* -所有图像文件都被接受
MIME_type - A valid MIME type, with no parameters. Look at IANA MIME types for a complete list of standard MIME types
MIME_type——有效的MIME类型,没有参数。查看IANA MIME类型,以获得标准MIME类型的完整列表。
#7
0
for image write this
图像写这
<input type=file accept="image/*">
For other, You can use the accept attribute on your form to suggest to the browser to restrict certain types. However, you'll want to re-validate in your server-side code to make sure. Never trust what the client sends you
另一方面,您可以使用表单上的accept属性来建议浏览器限制某些类型。但是,您需要在服务器端代码中重新验证以确保。永远不要相信客户给你的信息