public function csv()
{
$title = 'cnepss';
$headArr = ['qikan_id'=>'id','qikan_title'=>'标题','qc_name'=>'分类'];
$this->exportCommon($title,$headArr,$conduct);
}
/**
* 导出
* @param $title 导出的标题
* @param $headArr 导出内容表头
* @param $exportData 导出数据内容
* @createTime:18-5-10 上午10:46
* @author:lvqiang
*/
public function exportCommon($title, $headArr, $exportData)
{
$total = count($exportData);
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=" . iconv("UTF-8", "GB18030", $title) . ".csv");
$fp = fopen('php://output', 'a');
$headName = array_keys($headArr);
$headValue = array_values($headArr);
fputcsv($fp, $headValue);
$size = 2000;
$groupNum = ceil($total / $size);
for ($i = 0; $i <= $groupNum; $i++) {
$exportDataTemp = array_slice($exportData, $size * $i, $size);
foreach ($exportDataTemp as $item) {
$rows = array();
foreach ($headName as $name) {
$rows[] = $item[$name];
}
// die;
fputcsv($fp, $rows);
}
ob_flush();
flush();
}
die;
}