如何使用CSV MIME类型? [英] How to use the CSV MIME-type?

查看:971
本文介绍了如何使用CSV MIME类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我正在开发的网络应用程序中,用户可以点击指向CSV文件的链接。没有为mime类型设置的标题,所以浏览器只是将其作为文本。我想将此文件作为.csv文件发送,因此用户可以直接用calc,excel,gnumeric等打开它。

In a web application I am working on, the user can click on a link to a CSV file. There is no header set for the mime-type, so the browser just renders it as text. I would like for this file to be sent as a .csv file, so the user can directly open it with calc, excel, gnumeric, etc.

header('Content-Type: text/csv');
echo "cell 1, cell 2";

这段代码在我的计算机上正常工作(这不是总是这样)不能在另一台计算机上工作。

This code works as expected on my computer (Isn't that how it always is?) but does not work on another computer.

我的浏览器是每晚构建的FF 3.0.1(在linux上)。它不工作的浏览器是IE 7和FF 3.0(在Windows上)

My browser is a nightly build of FF 3.0.1 (on linux). The browsers it did not work in were IE 7 and FF 3.0 (on windows)

有没有我不知道的怪癖?

Are there any quirks I am unaware of?

推荐答案

您可以通过执行以下操作来强制浏览器打开另存为...对话框:

You could try to force the browser to open a "Save As..." dialog by doing something like:

header('Content-type: text/csv');
header('Content-disposition: attachment;filename=MyVerySpecial.csv');
echo "cell 1, cell 2";

哪些适用于大多数主流浏览器。

Which should work across most major browsers.

这篇关于如何使用CSV MIME类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆