我正在使用查询生成文件
SELECT * INTO OUTFILE " . "'c:/myfile.csv'" . " FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' FROM sample
我的文件现在位于C:/myfile.csv中。我希望用户下载该文件。我怎样才能做到这一点?
答案 0 :(得分:2)
你可以:
在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
答案 1 :(得分:2)
您需要在标头中设置Content-disposition: attachment
。在php中,使用header函数来实现此目的。
答案 2 :(得分:1)
if(!$fdl=@fopen($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);
}