当前位置: 移动技术网 > IT编程>开发语言>PHP > PHP7导出Excel报ERR_EMPTY_RESPONSE解决方法

PHP7导出Excel报ERR_EMPTY_RESPONSE解决方法

2019年07月19日  | 移动技术网IT编程  | 我要评论

php在本机可以正常导出excel,在上linux就提示err_empty_response,下面说一下怎么不降版本还能正常导出excel,解决上面的问题。

使用导出excel的时候显示错误页面提示如下,这时候发现上传excel都可以正常读取数据,只是导出的时候不可以。

我这里使用的php版本是7.1。phpexcel版本用的是1.8.1。github地址:

https://github.com/phpoffice/phpexcel/tree/1.8.1。可以看到作者已经3年没更新过了。

将phpexcel里面的class内容都拷贝到thinkphp的vendor目录下。重命名为phpexcel。也就是将之前老的插件换成这个1.8.1的版本。

具体怎么写excel和引入插件我就不说了。说下代码方面的写法。

问题其实集中出现在excel输出这里。(下面是成功导出excel的写法,前面生成excel的部分略去了)定义头部后直接输出。

$filename = "模板文件".date("ymdhis").rand(1000,9999);$filename = iconv("utf-8", "gb2312", $filename);header("pragma: public");header("expires: 0");header("cache-control:must-revalidate, post-check=0, pre-check=0");header("content-type:application/force-download");header("content-type:application/vnd.ms-execl");header("content-type:application/octet-stream");header("content-type:application/download");;header('content-disposition:attachment;filename='.$filename.'.xls');header("content-transfer-encoding:binary");$objwriter->save('php://output');

也可以使用phpspreadsheet来读写excel。

github:https://github.com/phpoffice/phpspreadsheet

文档:https://phpspreadsheet.readthedocs.io/en/develop/

以上就是关于php7导出excel报err_empty_response的相关解决步骤和方法,感谢大家的阅读和对移动技术网的支持。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网