将 csv 保存为附件文件 PHP+Apache 设置不起作用

发布于 2024-07-18 08:15:10 字数 466 浏览 2 评论 0原文

我有一个有趣的问题,我认为与服务器有关。 我希望当用户单击按钮时将 CSV 数据保存为 CSV 文件。 它在我的开发服务器上运行良好,但在生产中它只是将内容回显到页面。 我的猜测是这一定是服务器问题,但我真的不确定它可能是什么。 GZIP 会影响这个吗?

我的标头代码如下:

header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Length: " . strlen($out));
header("Content-type: text/x-csv");
header("Content-Disposition: attachment; filename=$filename");
echo $out;

因此上面的代码适用于开发服务器,而在生产环境中只会将 CSV 回显到页面。 有任何想法吗?

I have a interesting problem that I think is server related. I want CSV data to be saved as a CSV file when a user clicks a button. It works fine on my development server, but on the production it just echo's the content to the page. My guess is that it must be a server issue, but I'm really not sure what it could be. Can GZIP affect this?

My header code is as follows:

header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Length: " . strlen($out));
header("Content-type: text/x-csv");
header("Content-Disposition: attachment; filename=$filename");
echo $out;

So this code above works on a development server and on the production will just echo the CSV to the page. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

病女 2024-07-25 08:15:10

我唯一能想到的就是哑剧类型。 从一台服务器转移到另一台服务器时,我遇到了一些 MIME 类型问题(尤其是 .flv 文件)。

我用于 .csv 文件的是 application/octet-stream

希望有帮助

The only thing that I can think of is the mime-type. I've had some problems with mime-types (especially with .flv files) when moving from one server to another.

What I've used for .csv files is application/octet-stream.

Hope that helps

绻影浮沉 2024-07-25 08:15:10

是的,我猜这也是哑剧类型。 您可能想尝试 csv 特定的“text/csv”(RFC 4180) 或通用的“application/octet-stream”。

Yeah I'd guess it's the mime-type as well. You may want to try the csv specific "text/csv" (RFC 4180) or the generic "application/octet-stream".

放飞的风筝 2024-07-25 08:15:10

只需使用 Wireshark (http://www.wireshark.org) 并捕获这两种情况的 HTTP 流量,寻找差异。 Fiddler 也应该工作

Just use Wireshark (http://www.wireshark.org) and capture the HTTP-traffic for both cases and look for differences. Fiddler is also supposed to work

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文