如何获取csv文件在IE上下载?工程在firefox [英] How do I get csv file to download on IE? Works on firefox

查看:357
本文介绍了如何获取csv文件在IE上下载?工程在firefox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我挣扎着一个奇怪的错误。我有一个简单的网络应用程序抓取从一个数据库的东西,然后输出它作为一个可下载的CSV文件。它工作在firefox和chrome,但IE无法将其识别为一个csv文件(认为它是一个html文件),当我单击保存我得到的错误,无法从{name of site}下载{name of file}无法打开此网站...

I'm struggling with an odd error. I have a simple web app that grabs stuff from a DB then outputs it as a downloadable csv file. It works on firefox and chrome, but IE fails to recognize it as a csv file (thinking it is a html fle) and when I click save I get the error, "Unable to download {name of file} from {name of site}. Unable to open this internet site. ..."

代码:

session_start();

//some logic goes here...  

//generate csv header  
header("Content-type: application/octet-stream");  
header("Content-Disposition: attachment; filename=exportevent.csv");  
header("Pragma: no-cache");  
header("Expires: 0");  

echo "Event: " . $event_title . "\n";  

//print the column names  
echo "Last Name, First Name, Company \n";  

while($row = mysql_fetch_assoc($result))  
{  
    echo $row['atlname'] . ',' . $row['atfname'] . ',' . $row['atcompany'] . "\n";      
}

我已经玩过内容类型了,没有效果。

I've played around with the content-type a whole bunch, but that had no effect.

更新:我试过text / csv,application / vnd.ms-excel(及其变体),text / plain,

Update: I've tried text/csv, application/vnd.ms-excel (and variations of this), text/plain, and some others that I now forget with no luck.

更新2:连接已结束。

这是IE8 btw。 SSL。

Update 2: The connection is over SSL.

推荐答案

我们不喜欢IE吗? :)

Don't we love IE? :)

尝试使用以下标题:

  header("Pragma: public");
  header("Expires: 0");
  header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  header("Cache-Control: private",false);
  header("Content-Type: application/octet-stream");
  header("Content-Disposition: attachment; filename=\"exportevent.csv\";" );
  header("Content-Transfer-Encoding: binary"); 

我认为八位字节流内容类型强制IE下载文件。

I think that the octet-stream content type forces IE to download the file.

这篇关于如何获取csv文件在IE上下载?工程在firefox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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