php下载excel无法打开的解决方法
php下载excel文件,
1、在下载的过程中不要 输出任何非文件信息,比如 echo log信息。 否则下载后的文件无法打开,提示格式错误或者文件被破坏。
2、 输出的excel格式一定要和后缀名保存一直,否也会提示格式错误或者文件被破坏
if (file_exists(CACHE_PATH . $file_name)){
//$this->logger->error('file realpath:'.realpath(CACHE_PATH . $file_name));
header( 'Pragma: public' );
header( 'Expires: 0' );
header( 'Content-Encoding: none' );
header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
header( 'Cache-Control: public' );
header( 'Content-Type: application/vnd.ms-excel');
header( 'Content-Description: File Transfer' );
header( 'Content-Disposition: attachment; filename=' . $file_name );
header( 'Content-Transfer-Encoding: binary' );
header( 'Content-Length: ' . filesize ( CACHE_PATH . $file_name ) );
readfile ( CACHE_PATH . $file_name );
} else {
$this->logger->error('export model :'.$id.' 错误:未生产文件');
echo '';
}相关阅读:
jQuery侧边栏实现代码
Win10 Mobile预览版10572:拨号界面支持号码自由编辑(演示视频)
yii2缓存Caching基本用法示例
在Ubuntu系统中使用APT-mirror本地软件仓库的教程
javascript与css3动画结合使用小结
在Win10平板模式下如何关闭应用程序?
javascript实现列表滚动的方法
php项目中百度 UEditor 简单安装调试和调用
详解Linux系统中的守护进程
c语言实现冒泡排序、希尔排序等多种算法示例
IOS展开三级列表效果示例
HTTP 304错误的详细讲解
jquery表单验证需要做些什么
Smarty分页实现方法完整实例