我正在使用查询生成文件
SELECT * INTO OUTFILE " . "'c:/myfile.csv'" . " FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' FROM sample
我的文件现在位于 C:/myfile.csv 中。我希望用户下载文件。我怎样才能做到这一点?
我正在使用查询生成文件
SELECT * INTO OUTFILE " . "'c:/myfile.csv'" . " FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' FROM sample
我的文件现在位于 C:/myfile.csv 中。我希望用户下载文件。我怎样才能做到这一点?
你可以 :
在 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 中,使用 header 函数来实现这一点。
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);
}