原文链接:https://blog.csdn.net/bkcnl/article/details/76152505
public function getxiajiueser(){ $id = request()->param('id');$stmt = Db::name('tablename')->field('xxx,yyy,xyxy')->where('id',$id)->select(); header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="abc.csv"'); header('Cache-Control: max-age=0'); $fp = fopen('php://output', 'a'); $head = array('titleone', 'titletwo'); foreach ($head as $i => $v) { $head[$i] = iconv('utf-8', 'gb2312', $v); } fputcsv($fp, $head); foreach($stmt as $k=>$v){ fputcsv($fp, $v); } }