【发布时间】:2016-10-17 21:37:21
【问题描述】:
$file="csv.php?task=whovotedwho&election=7";
$filename = "whovotedwho-election7.csv";
if (file_exists("trash.png")) {
header('Content-Description: File Transfer');
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="'.($filename).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize("trash.png"));
readfile($file);
exit;
} else { echo "file does not exist"; }
我在下载的 csv 中得到这个结果。
【问题讨论】:
-
看起来你安装了几个扩展(比如 x-debug),其中一个有错误并执行双 html 编码
-
php 文件是否有
readfile等效项? -
您没有下载 CSV 文件。看看你得到了什么,这是一条错误消息,说
readfile()失败。 -
你为什么使用
filesize("trash.png")?这与下载的 CSV 文件的大小有什么关系? -
您不能将带有查询字符串参数的 url 传递给
include。你试过readfile("http://www.example.com/csv.php?task=whovotedwho&election=7")