使用PHP创建和下载CSV [英] Creating and downloading CSV with PHP

查看:140
本文介绍了使用PHP创建和下载CSV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PHP从数据库查询创建CSV文件。
我运行查询,设置标题,然后在Firefox中加载页面,文件提示下载并在excel中打开就像它应该的那样。
当我在IE中尝试时,我收到一条错误消息 Internet Explorer无法从www.website.com下载ReportPrint.php。

Internet Explorer无法打开这个互联网网站。请求的网站不可用或无法找到。请稍后再试。


不知道可以采取哪些措施来解决此问题。

I'm using PHP to create a CSV file from a database query. I run the query, set the headers, and load the page up in Firefox and the file promps for download and opens in excel just like it's supposed to. When I try it in IE, I get an error saying Internet Explorer cannot download ReportPrint.php from www.website.com.
Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later.

Not sure what can be done to fix this.

header('Content-Description: File Transfer');
header("Content-Type: application/csv") ;
header("Content-Disposition: attachment; filename=Report.csv");
header("Pragma: no-cache");
header("Expires: 0");

echo "record1,record2,record3\n";


推荐答案

删除 Pragma:否-cache 标题。此标头阻止IE下载文件。

Remove the Pragma: no-cache header. This header prevents IE from downloading the file.

这篇关于使用PHP创建和下载CSV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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