From 82afa60d12f94ee3b78da7cd98a516608a483e04 Mon Sep 17 00:00:00 2001 From: chenzhi Date: Wed, 25 Dec 2019 15:37:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=8E=A9=E5=AE=B6=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=AF=BC=E5=87=BA2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Application/Admin/Common/extend.php | 70 ++++++++++++++--------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/Application/Admin/Common/extend.php b/Application/Admin/Common/extend.php index d832441f3..aa9ee0cc8 100644 --- a/Application/Admin/Common/extend.php +++ b/Application/Admin/Common/extend.php @@ -1734,40 +1734,40 @@ function getOffspringByPromoteId($promote_id = null) { * @return void */ function data2csv(&$data,$title,$fields){ -  set_time_limit(0); -    ini_set('memory_limit', '-1'); //设置内存不受限制 -    $csvFileName = $title.'.csv'; -    //设置好告诉浏览器要下载excel文件的headers -    header('Content-Description: File Transfer'); -    header('Content-Type: application/vnd.ms-excel;charset=utf-8'); -    header('Content-Disposition: attachment; filename="'. $csvFileName .'"'); -    header('Expires: 0'); -    header('Cache-Control: must-revalidate'); -    header('Pragma: public'); -    $fp = fopen('php://output', 'a');//打开output流 -    fwrite($fp, chr(0xEF).chr(0xBB).chr(0xBF));//转码,防止乱码 -    $field = array_keys($fields); -    //生成首行 -    $header = array_values($fields); -    fputcsv($fp, $header); - -    $index = 0; -    foreach ($data as $row) { -        $a = []; -        foreach($field as $k=>$v){ -            // $a[$v] = $row[$v] . "\t";//防止格式错误 -            $a[$v] = $row[$v]; -        } -        if ($index == 10000) { //每次写入1000条数据清除内存 -            $index = 0; -            ob_flush();//清除内存 -            flush(); -        } -        $index++; -        fputcsv($fp, $a); -    } -    ob_flush(); -    fclose($fp);  //每生成一个文件关闭 -    die(); + set_time_limit(0); + ini_set('memory_limit', '-1'); //设置内存不受限制 + $csvFileName = $title.'.csv'; + //设置好告诉浏览器要下载excel文件的headers + header('Content-Description: File Transfer'); + header('Content-Type: application/vnd.ms-excel;charset=utf-8'); + header('Content-Disposition: attachment; filename="'. $csvFileName .'"'); + header('Expires: 0'); + header('Cache-Control: must-revalidate'); + header('Pragma: public'); + $fp = fopen('php://output', 'a');//打开output流 + fwrite($fp, chr(0xEF).chr(0xBB).chr(0xBF));//转码,防止乱码 + $field = array_keys($fields); + //生成首行 + $header = array_values($fields); + fputcsv($fp, $header); + + $index = 0; + foreach ($data as $row) { + $a = []; + foreach($field as $k=>$v){ + // $a[$v] = $row[$v] . "\t";//防止格式错误 + $a[$v] = $row[$v]; + } + if ($index == 10000) { //每次写入1000条数据清除内存 + $index = 0; + ob_flush();//清除内存 + flush(); + } + $index++; + fputcsv($fp, $a); + } + ob_flush(); + fclose($fp); //每生成一个文件关闭 + die(); } ?>