在Laravel中使用PhpSpreadsheet导出excel时一般有两种方案
$writer->save('php://output');//直接输出到浏览器
$writer->save($path); //先保存为文件
echo file_get_contents($path);//再输出文件
但经过测试,这两种方案都依赖着php的临时文件目录,因此都需要在php.ini中将临时文件目录添加至open_basedir 中
[HOST=location]
open_basedir=/tmp
若要添加多个路径请使用:
间隔
[HOST=location]
open_basedir=/tmp:/home/www