【发布时间】:2010-11-30 17:40:30
【问题描述】:
我的服务器上有一个 CSV 文件。如果用户点击应该下载的链接,但它会在我的浏览器窗口中打开。
我的代码如下所示
<a href="files/csv/example/example.csv">
Click here to download an example of the "CSV" file
</a>
这是一个普通的网络服务器,我的所有开发工作都在其中。
我尝试了类似的方法:
<a href="files/csv/example/csv.php">
Click here to download an example of the "CSV" file
</a>
现在是我的csv.php 文件的内容:
header('Content-Type: application/csv');
header('Content-Disposition: attachment; filename=example.csv');
header('Pragma: no-cache');
现在我的问题是它正在下载,但不是我的 CSV 文件。它会创建一个新文件。
【问题讨论】:
-
这与 PHP 有什么关系?
-
你忘记输出文件内容了。
-
在下面更新了我的答案,为您的新问题提供了解决方案
-
不使用php可以吗?
-
你可以在这里找到另一个好的答案:stackoverflow.com/questions/10934022/…