使用$ write-> save的Phpspreadsheet无法正常工作-错误处理

时间:2019-06-19 13:27:40

标签: php error-handling phpspreadsheet

我已经在Wordpress网站上编写了一个脚本,该脚本将ajax调用发送到functions.php,并创建了一个excel文件。 测试时遇到错误:
ZipArchive::close(): Failure to create temporary file 我意识到文件路径必须是系统路径,因此我对其进行了修复,此外,我的Ajax调用收到了error 500的响应,因此我想捕获错误并在响应中发送ajax错误。

我尝试了2种方法:
1。

if( $writer->save( $file_path ) ) {
        wp_send_json( 'Success.' );
}
wp_send_json( 'Error creating report.' );

wp_send_json()-将JSON响应发送回AJAX请求,然后die()。

2。

try {
    $writer->save( $file_path );
}
catch( Exception $e ) {
    wp_send_json( 'Message: ' .$e->getMessage() );
}
wp_send_json( 'Success.' );

这些方法都不起作用。我想念什么?如何捕捉这些错误?为了模拟错误,我故意输入了错误的路径。

谢谢

1 个答案:

答案 0 :(得分:0)

ZipArchive :: close()错误表明您要写入的路径的权限错误。

相关问题