PhpSpreadsheet无法保存到服务器

时间:2018-06-28 06:30:46

标签: php codeigniter phpspreadsheet

我正在尝试使用PhpSpreadsheet编写Excel文件并将其保存到文件服务器。 这是我的代码:

$path = 'http://192.168.3.81/erpFile/'.time().'.xlsx';
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Excel2007');
$writer->save($path);

但是我收到以下错误消息:

A PHP Error was encountered
Severity: Warning
Message: ZipArchive::close(): Failure to create temporary file: No such file or directory

An uncaught Exception was encountered
Type: PhpOffice\PhpSpreadsheet\Writer\Exception
Message: Could not close zip file http://192.168.3.81/erpFile/1530169174.xlsx.

目录权限已设置为777。请提供帮助。谢谢。

1 个答案:

答案 0 :(得分:2)

您必须使用系统文件路径。像这样:

$path = FCPATH.'erpFile'.DIRECTORY_SEPARATOR.time().'.xlsx';