我已经编写了这段代码,但它只生成csv 文件,而不是在目录中上传。
$file = 'export';
$csv_output .= "CustID,CustName,CustMobile,CustEmail\n";
$sql = "select CustID,CustName,CustMobile,CustEmail from dep_customer_details LIMIT 0,10";
$res = mysql_query($sql);
while ($row = mysql_fetch_row($res)) {
for ($j=0;$j<$res;$j++) {
$csv_output .= $row[$j].", ";
}
$csv_output .= "\n";
}
$filename = $file."_".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header("Content-disposition: filename=".$filename.".csv");
print $csv_output;
$uploaddir = dirname(__FILE__) .'/csv/';
$uploadfile = $uploaddir.$filename;
move_uploaded_file($filename,$uploadfile);