我使用以下方式尝试将数据导出到 csv 文件,我使用的方法来自以下链接Problem in Export csv file in php,但是当我尝试导出文件时,系统回复我 no such file can被阅读,所以我想问在执行代码之前我必须先打开一个result.csv吗?或者文件result.csv已经生成,但是在错误的目录下,如果是这个原因,请问如何定义文件应该创建的目录。
$result = mysql_query("SELECT TechName, ClientName, SiteName, Time, Type
INTO OUTFILE 'result.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED by '\"'
LINES TERMINATED BY '\n'
FROM Tech AS T, Client AS C, Site AS S, Log AS L
WHERE T.TechID=L.TechID AND C.ClientID=L.ClientID AND S.SiteID=L.SiteID
ORDER BY L.Time DESC");
$Time = date('Y_m_d_H_i');
$fileName = "Report_".$Time.".csv";
header('Content-type: text/csv');
header('Content-Disposition: attachment; filename="'.$fileName.'"');
readfile('result.csv');