尝试在CodeIgniter 3中使用Phpencil Sheet导出xlsx文件。当我运行URL时,它显示无法访问该网站。网站可能暂时关闭,或者它可能已永久移动到一个新的网址。
控制器
require 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
function generateLR(){
// create file name
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="result.xlsx');
header('Cache-Control: max-age=0');
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello World !');
$writer = new Xlsx($spreadsheet);
$writer->save('php://output');
}
但是如果我尝试在本地保存$writer->save('hello world.xlsx');
。输出成功保存到项目文件夹中。
也尝试使用IOFactory,但结果是一样的:网站暂时关闭
require 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\IOFactory;
function generateLR(){
// create file name
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="result.xlsx');
header('Cache-Control: max-age=0');
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello World !');
$writer = IOFactory::createWriter($spreadsheet,'Xlsx');
$writer->save('php://output');
}
错误图片
是否存在env问题?
1条答案
按热度按时间jw5wzhpr1#
找到答案了。问题是
sys_get_temp_dir()
的权限。我的临时文件夹在Macbook中默认无法访问。更改权限后。可以在localhost中创建Excel