diff --git a/Application/Admin/Common/extend.php b/Application/Admin/Common/extend.php index 1d6b3fb72..686627fe2 100644 --- a/Application/Admin/Common/extend.php +++ b/Application/Admin/Common/extend.php @@ -1541,4 +1541,25 @@ function getGameList($partner_id) { 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(); +} ?>