Php 为什么是&;转换为&;amp;放大器?
我在下载的csv中得到这个结果 这是:Php 为什么是&;转换为&;amp;放大器?,php,file,csv,Php,File,Csv,我在下载的csv中得到这个结果 这是: $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'); h
$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"; }
它不是像http://example.com/csv.php...
,所以当readfile()启动时,它正在执行一个本地文件请求,并寻找一个名为csv.php?tasketc的文件…
它不是在执行一个http请求-它不能。您没有提供将http请求发送到的协议或主机
PHP不像您的浏览器,类似于
的内容在内部被翻译成
坦白地说,即使你有一个完整的URL,这样做也是非常痛苦的——你已经在执行http请求的同一台服务器上执行代码了,所以这就像跳上你的车,在城市里行驶500英里,这样你就可以把车停在起点左侧1英尺的地方
你在错误中发现的是原始HTML。由于文件名中包含
&
,因此必须对其进行HTML编码,以使其在输出中显示为文本&
,而不是呈现为HTML实体。看起来您安装了多个扩展名(如x-debug),其中一个有bug并执行双重html编码是否有php文件的readfile
等效文件?您没有下载CSV文件。看看你得到了什么,它是一条错误消息,说readfile()
失败了。为什么要使用filesize(“trash.png”)
?这与正在下载的CSV文件的大小有什么关系?您不能将带有查询字符串参数的url传递给include
。您是否尝试了readfile(“http://www.example.com/csv.php?task=whovotedwho&election=7“”
$file="csv.php?task=whovotedwho&election=7";