我想提供一个 Excel 文件以供下载 PhpSpreadsheet
这是我的代码:
require 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello World !');
$writer = new Xlsx($spreadsheet);
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="hello_world.xlsx"');
$writer->save("php://output");
我收到以下错误消息:
PHP Warning: ZipArchive::close(): Failure to create temporary file: No such file or directory in /Users/sg/GitWorkingCopies/xxx1/xxx2/library/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xlsx.php on line 374
PHP Fatal error: Uncaught exception 'PhpOffice\PhpSpreadsheet\Writer\Exception' with message 'Could not close zip file php://output.' in /Users/sg/GitWorkingCopies/xxx1/xxx2/library/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xlsx.php:375
\PhpOffice\PhpSpreadsheet\Writer\Xlsx 在写入 php://output 时使用临时存储。默认情况下,临时文件存储在脚本的工作目录中。当没有访问权限时,它会回退到操作系统的临时文件位置。
upload_tmp_dir 是:/Applications/XAMPP/xamppfiles/temp/
我必须检查哪些文件夹权限?或者是什么导致了问题?