手机
当前位置:查字典教程网 >编程开发 >php教程 >php下载excel无法打开的解决方法
php下载excel无法打开的解决方法
摘要:php下载excel文件,1、在下载的过程中不要输出任何非文件信息,比如echolog信息。否则下载后的文件无法打开,提示格式错误或者文件被...

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 '<script>alert('export error, file not exists!')</script>';

}

【php下载excel无法打开的解决方法】相关文章:

php 字母大小写转换的方法

php格式化电话号码的方法

php获取twitter最新消息的方法

php常见的页面跳转方法汇总

php转换颜色为其反色的方法

php对象和数组相互转换的方法

php函数重载的替代方法

php使用array_search函数实现数组查找的方法

phpmyadmin 数据库导入2048kb的解决办法

php中检查email完整性

精品推荐
分类导航