简体   繁体   English

输入元素的自定义mime类型

[英]Custom mime type for input element

According to the spec at https://www.w3.org/wiki/HTML/Elements/input/file 根据https://www.w3.org/wiki/HTML/Elements/input/file上的规范

The "accept" attribute is a series of MIME types. “ accept”属性是一系列MIME类型。

In this case (ie the file is not coming from a server), is it possible to set a custom MIME type for a certain file extension or binary file peeking (eg some procedure to read the header)? 在这种情况下(即文件不是来自服务器),是否可以为某个文件扩展名或二进制文件窥视设置自定义MIME类型(例如,读取标头的某些过程)?

Yes, you can set custom MIME types. 是的,你可以设置自定义MIME类型。

The Living Standard specification states "The accept attribute may be specified to provide user agents with a hint of what file types will be accepted." 生活标准规范指出: “可以指定accept属性,以向用户代理提示将接受哪种文件类型。”

To use this, use the following <input type="file" name="example" accept= "your-custom-extension-1, your-custom-extension-2, your-custom-extension-3"> 要使用此功能,请使用以下<input type="file" name="example" accept= "your-custom-extension-1, your-custom-extension-2, your-custom-extension-3">

In addition, read the following statement about the accept attribute : "If the value of the type attribute is file, then this attribute will indicate the types of files that the server accepts, otherwise it will be ignored". 另外,请阅读以下有关accept 属性的声明:“如果type属性的值为file,则此属性将指示服务器接受的文件类型,否则将被忽略”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM