我使用查詢生成文件如何強制用戶下載(另存爲對話框)剛剛生成的文件
SELECT * INTO OUTFILE " . "'c:/myfile.csv'" . " FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' FROM sample
我的文件現在位於C:/myfile.csv中。我希望用戶下載該文件。我怎樣才能做到這一點。
Expers請幫忙。
我使用查詢生成文件如何強制用戶下載(另存爲對話框)剛剛生成的文件
SELECT * INTO OUTFILE " . "'c:/myfile.csv'" . " FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' FROM sample
我的文件現在位於C:/myfile.csv中。我希望用戶下載該文件。我怎樣才能做到這一點。
Expers請幫忙。
,你可以:
在PHP中,這樣的事情應該做的伎倆:
header('Content-Disposition: attachment; filename="my-file.csv"'); // The name which will be suggested to the user
readfile('c:/myfile.csv'); // outputs the content of the file
你需要設置Content-disposition: attachment
在頭中。在PHP中,使用頭功能來實現這一點。
if([email protected]($fileString,'r')){
die("Cannot Open File!");
} else {
header("Cache-Control: ");// leave blank to avoid IE errors
header("Pragma: ");// leave blank to avoid IE errors
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=\"".$fileName."\"");
header("Content-length:".(string)(filesize($fileString)));
sleep(1);
fpassthru($fdl);
}
http://stackoverflow.com/search?q=[php]+force+download – 2011-03-31 17:39:14
對不起,創建重複的朋友......真的很抱歉 – Rajasekar 2011-03-31 17:44:48