我的服务器上有一个CSV文件.如果用户点击了应该下载的链接,而是在我的浏览器窗口中打开它.
我的代码如下所示
<a href="files/csv/example/example.csv">
Click here to download an example of the "CSV" file
</a>
Run Code Online (Sandbox Code Playgroud)
这是一个普通的网络服务器,我可以完成所有的开发工作.
我尝试过类似的东西:
<a href="files/csv/example/csv.php">
Click here to download an example of the "CSV" file
</a>
Run Code Online (Sandbox Code Playgroud)
现在我的csv.php文件的内容:
header('Content-Type: application/csv');
header('Content-Disposition: attachment; filename=example.csv');
header('Pragma: no-cache');
Run Code Online (Sandbox Code Playgroud)
现在我的问题是它正在下载,但不是我的CSV文件.它会创建一个新文件.