[英]preventing £ from being echoed: why doesn't the actual symbol show?
[英]Why is & being converted to &amp?
$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中得到此結果。
這個:
$file="csv.php?task=whovotedwho&election=7";
它不是http://example.com/csv.php...
類的完整/絕對URL,因此當readfile()啟動時,它正在執行LOCAL文件請求,並查找名稱實際上是csv.php?tasketc...
的文件。 csv.php?tasketc...
這不是在做一個HTTP請求-它不能。 您沒有提供該HTTP請求發送給TO的協議或主機。
PHP與您的瀏覽器不同,PHP在內部將諸如<img src=kittens.jpg>
內容翻譯為<img src="http://example.com/kittens.jpg">
。
坦白說,即使那里有完整的URL,這樣做也很痛苦-您已經在要執行http請求的確切SAME服務器上執行代碼,所以就像跳上車並開車500距離城市只有數英里,所以您可以將車停在起點處的左側1英尺處。
錯誤的根源在於原始HTML。 由於文件名中包含&
,因此必須對其進行HTML編碼,因此它在輸出中顯示為文字&
,而不是作為HTML實體呈現。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.