新增导出csv函数

master
chenzhi 5 years ago
parent e4b6cdea85
commit b743cd73e1

@ -1541,4 +1541,25 @@ function getGameList($partner_id) {
return $data; return $data;
} }
//导出csv 2019/12/20
function db2csv(&$data,$title,$header=false){
set_time_limit(0);
$filename = $title .'.csv';
$fp = fopen($filename, 'w'); //生成临时文件
fwrite($fp, chr(0xEF).chr(0xBB).chr(0xBF));//转码,防止乱码
if($header) fputcsv($fp, $header);
foreach ($data as $a) {
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();
}
?> ?>

Loading…
Cancel
Save