php下载excel无法打开的解决方法

2015-01-24信息快讯网

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

PHP错误Parse error: syntax error, unexpected end of file in test.php on line 12解决方法
解决cPanel无法安装php5.2.17
ThinkPHP之getField详解
ThinkPHP CURD方法之field方法详解
php的SimpleXML方法读写XML接口文件实例解析
浅析ThinkPHP中execute和query方法的区别
PHP中使用gettext解决国际化问题的例子(i18n)
Codeigniter上传图片出现“You did not select a file to upload”错误解决办法
让CodeIgniter的ellipsize()支持中文截断的方法
PHP使用Alexa API获取网站的Alexa排名例子
Codeigniter+PHPExcel实现导出数据到Excel文件
Codeigniter生成Excel文档的简单方法
php实现文件下载实例分享
在PHP中使用X-SendFile头让文件下载更快
PHP生成迅雷、快车、旋风等软件的下载链接代码实例
PHP写的资源下载防盗链类分享
php把数据表导出为Excel表的最简单、最快的方法(不用插件)
php实现文件下载功能的几个代码分享
php导出excel格式数据问题
php导出word文档与excel电子表格的简单示例代码
生成随机字符串和验证码的类的PHP实例
php calender(日历)二个版本代码示例(解决2038问题)
phpexcel导入excel数据使用方法实例
php生成excel列序号代码实例
php读取csv实现csv文件下载功能
php实现文件下载(支持中文文名)
利用phpExcel实现Excel数据的导入导出(全步骤详细解析)
php使浏览器直接下载pdf文件的方法
php使用exec shell命令注入的方法讲解
简单实用的.net DataTable导出Execl
php 强制下载文件实现代码
php导入导出excel实例
使用PHP下载CSS文件中的图片的代码
php读取excel文件的简单实例
©2014-2024 dbsqp.com