|
|
|
@ -1562,4 +1562,31 @@ function db2csv(&$data,$title,$header=false){
|
|
|
|
|
unlink($filename);
|
|
|
|
|
die();
|
|
|
|
|
}
|
|
|
|
|
//导出csv 新增字段排序功能
|
|
|
|
|
function data2csv(&$data,$title,$fields){
|
|
|
|
|
set_time_limit(0);
|
|
|
|
|
$filename = $title .'.csv';
|
|
|
|
|
$fp = fopen($filename, 'w'); //生成临时文件
|
|
|
|
|
fwrite($fp, chr(0xEF).chr(0xBB).chr(0xBF));//转码,防止乱码
|
|
|
|
|
|
|
|
|
|
$field = array_keys($fields);
|
|
|
|
|
$header = array_values($fields);
|
|
|
|
|
fputcsv($fp, $header);
|
|
|
|
|
foreach ($data as $row) {
|
|
|
|
|
$a = [];
|
|
|
|
|
foreach($field as $k=>$v){
|
|
|
|
|
$a[$v] = $row[$v];
|
|
|
|
|
}
|
|
|
|
|
fputcsv($fp, $a);
|
|
|
|
|
}
|
|
|
|
|
fclose($fp); //每生成一个文件关闭
|
|
|
|
|
//下载
|
|
|
|
|
header('Content-Type: application/vnd.ms-excel;charset=utf-8');
|
|
|
|
|
header('Content-Disposition: attachment;filename="' . $title . '.csv"');
|
|
|
|
|
header('Cache-Control: max-age=0');
|
|
|
|
|
header('Content-Length: ' . filesize($filename));
|
|
|
|
|
readfile($filename);
|
|
|
|
|
unlink($filename);
|
|
|
|
|
die();
|
|
|
|
|
}
|
|
|
|
|
?>
|
|
|
|
|