导出Excel php://output 直接返回response 第一次请求OK, 再请求第二次就报错了
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header("Content-Disposition: attachment;filename=".$Excel['fileName'].".xlsx");
header('Cache-Control: max-age=0');//禁止缓存
$writer = new Xlsx($spreadsheet);
$writer->save('php://output');
$c = ob_get_contents();
ob_flush();
flush();
$response = response();
$response->withHeaders([
'Content-Type' => 'application/vnd.ms-excel',
'Content-Disposition' => 'attachment;filename="'.$fileName.'"',
'Cache-Control' => 'max-age=0',
])->withBody($c);
ob_clean();
return $response;
Cannot modify header information - headers already sent by (output started at E:\\GitProject\\webman-admin\\BackEnd\\app\\common\\controller\\Manage.php:199)
第二次请求就报错了
window10
webman: 1.4.3
php: 7.4
解决了,原来是我在response之前输出了header内容