我应该为CSV使用什么MIME类型?

时间:2011-08-16 09:21:03

标签: csv http-headers mime-types

我看过application/csv使用了text/csv

有什么区别?有区别吗?只要请求匹配可用的内容,这是否重要?它们可以互换吗?

5 个答案:

答案 0 :(得分:535)

RFC 7111

有一个RFC覆盖它,并说要使用text/csv

此RFC更新RFC 4180。


Excel中

最近我发现了Excel application / vnd.ms-excel的显式mimetype。它于1996年在IANA注册。请注意提出的关于发件人怜悯以及违反您的机器的问题。

  

媒体类型:application / vnd.ms-excel

     

命名Microsoft Excel(tm)

     

必填参数:无

     

可选参数:名称

     

编码注意事项:base64首选

     

安全注意事项:与大多数应用程序类型一样,此数据是   旨在由理解数据的程序进行解释   收件人的系统。收件人需要了解他们所处的位置   发送者的“怜悯”,当收到这种类型的数据时,自此   数据将在他们的系统上执行,以及他们的安全性   机器可以被违反。

     

OID {org-id ms-files(4)ms-excel(3)}

     

对象类型电子表格

     

注释此媒体类型/ OID用于标识Microsoft   Excel通常(即独立于版本,子类型或平台格式)。

我不知道允许供应商扩展。查看this answer以了解更多信息 - 感谢starbeamrainbowlabs作为参考。

答案 1 :(得分:78)

您应该根据RFC 4180使用“text / csv”。

答案 2 :(得分:42)

MS Excel的奇怪行为: 如果我导出为“基于文本,以逗号分隔的格式(csv)”,这是我在网络服务器上传后获得的mime类型:

[name] => data.csv
[type] => application/vnd.ms-excel

因此,无论现有标准如何,微软似乎都在重新做自己的事情:https://en.wikipedia.org/wiki/Comma-separated_values

答案 3 :(得分:26)

我的用户可以上传CSV文件,而//connect and fetch all entries from the filter table $filterproducts = $dbh->prepare("SELECT * FROM table_filter_selection ORDER BY filter ASC"); $filterproducts->execute(); $filterselect = $filterproducts->fetchAll(); //for each entry found loop through a second loop foreach($filterselect as $rows){ $wildcard = "%" . $rows['filter'] . "%"; //make a variable into a regex of the row $query = "PRODUCT_NAME LIKE '%" . implode("%' AND PRODUCT_NAME LIKE '%", $breakdown) . "%'"; $sqlstring= "SELECT * FROM product_list WHERE PRODUCT_NAME LIKE :filterfind AND " . $query; $searchproducts = $dbh->prepare($sqlstring); $searchproducts->bindParam(":filterfind", $wildcard, PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $searchproducts->execute(); //search for all products that match the wildcard AND the current filter foreach($searchproducts as $rows2){ //for every one found, make a row. echo "<tr><td>" . $rows2['SKU'] ." <strong style='font-style: italic;'>". $rows2['COMMENTS'] . "</strong><td/><td>". $rows2['PRODUCT_NAME'] ."</td><td>". $rows2['QTY'] . "</td></tr>"; } } text/csv目前尚未显示。这些是通过finfo()确定的:

application/csv

这些是通过浏览器传输的内容:

text/plain
text/x-csv

未出现以下类型,但可能:

text/plain
application/vnd.ms-excel
text/x-csv

答案 4 :(得分:1)

对于那些正在努力使用Google API mimeType for * .csv文件的人。 我找到了google api docs文件的MIME类型列表 (看看剪切结果)

&#13;
&#13;
<table border="1"><thead><tr><th>Google Doc Format</th><th>Conversion Format</th><th>Corresponding MIME type</th></tr></thead><tbody><tr><td>Documents</td><td>HTML</td><td>text/html</td></tr><tr></tr><tr><td></td><td>HTML (zipped)</td><td>application/zip</td></tr><tr><td></td><td>Plain text</td><td>text/plain</td></tr><tr><td></td><td>Rich text</td><td>application/rtf</td></tr><tr><td></td><td>Open Office doc</td><td>application/vnd.oasis.opendocument.text</td></tr><tr><td></td><td>PDF</td><td>application/pdf</td></tr><tr><td></td><td>MS Word document</td><td>application/vnd.openxmlformats-officedocument.wordprocessingml.document</td></tr><tr><td></td><td>EPUB</td><td>application/epub+zip</td></tr><tr><td>Spreadsheets</td><td>MS Excel</td><td>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</td></tr><tr><td></td><td>Open Office sheet</td><td>application/x-vnd.oasis.opendocument.spreadsheet</td></tr><tr><td></td><td>PDF</td><td>application/pdf</td></tr><tr><td></td><td>CSV (first sheet only)</td><td>text/csv</td></tr><tr><td></td><td>TSV (first sheet only)</td><td>text/tab-separated-values</td></tr><tr><td></td><td>HTML (zipped)</td><td>application/zip</td></tr><tr></tr><tr><td>Drawings</td><td>JPEG</td><td>image/jpeg</td></tr><tr><td></td><td>PNG</td><td>image/png</td></tr><tr><td></td><td>SVG</td><td>image/svg+xml</td></tr><tr><td></td><td>PDF</td><td>application/pdf</td></tr><tr><td>Presentations</td><td>MS PowerPoint</td><td>application/vnd.openxmlformats-officedocument.presentationml.presentation</td></tr><tr><td></td><td>Open Office presentation</td><td>application/vnd.oasis.opendocument.presentation</td></tr><tr></tr><tr><td></td><td>PDF</td><td>application/pdf</td></tr><tr><td></td><td>Plain text</td><td>text/plain</td></tr><tr><td>Apps Scripts</td><td>JSON</td><td>application/vnd.google-apps.script+json</td></tr></tbody></table>
&#13;
&#13;
&#13;

来源: https://developers.google.com/drive/v3/web/manage-downloads#downloading_google_documents 下表: &#34; Google Doc格式和支持的导出MIME类型相互映射,如下所示&#34;

还有另一个清单

&#13;
&#13;
<table border="1"><thead><tr><th>MIME Type</th><th>Description</th></tr></thead><tbody><tr><td><code><span>application/vnd.<wbr>google-apps.<wbr>audio</span></code></td><td></td></tr><tr><td><code><span>application/vnd.<wbr>google-apps.<wbr>document</span></code></td><td>Google Docs</td></tr><tr><td><code><span>application/vnd.<wbr>google-apps.<wbr>drawing</span></code></td><td>Google Drawing</td></tr><tr><td><code><span>application/vnd.<wbr>google-apps.<wbr>file</span></code></td><td>Google Drive file</td></tr><tr><td><code><span>application/vnd.<wbr>google-apps.<wbr>folder</span></code></td><td>Google Drive folder</td></tr><tr><td><code><span>application/vnd.<wbr>google-apps.<wbr>form</span></code></td><td>Google Forms</td></tr><tr><td><code><span>application/vnd.<wbr>google-apps.<wbr>fusiontable</span></code></td><td>Google Fusion Tables</td></tr><tr><td><code><span>application/vnd.<wbr>google-apps.<wbr>map</span></code></td><td>Google My Maps</td></tr><tr><td><code><span>application/vnd.<wbr>google-apps.<wbr>photo</span></code></td><td></td></tr><tr><td><code><span>application/vnd.<wbr>google-apps.<wbr>presentation</span></code></td><td>Google Slides</td></tr><tr><td><code><span>application/vnd.<wbr>google-apps.<wbr>script</span></code></td><td>Google Apps Scripts</td></tr><tr><td><code><span>application/vnd.<wbr>google-apps.<wbr>site</span></code></td><td>Google Sites</td></tr><tr><td><code><span>application/vnd.<wbr>google-apps.<wbr>spreadsheet</span></code></td><td>Google Sheets</td></tr><tr><td><code><span>application/vnd.<wbr>google-apps.<wbr>unknown</span></code></td><td></td></tr><tr><td><code><span>application/vnd.<wbr>google-apps.<wbr>video</span></code></td><td></td></tr><tr><td><code><span>application/vnd.<wbr>google-apps.<wbr>drive-sdk</span></code></td><td>3rd party shortcut</td></tr></tbody></table>
&#13;
&#13;
&#13;

来源: https://developers.google.com/drive/v3/web/mime-types

但第一个对我的用例更有帮助..

快乐的编码;)