Home > Backend Development > PHP Tutorial > Solve the problem that Excel cannot be opened when downloaded by PHP

Solve the problem that Excel cannot be opened when downloaded by PHP

WBOY
Release: 2016-07-25 08:55:26
Original
1976 people have browsed it
  1. /**
  2. * PHP code to implement excel file download
  3. * edit: bbs.it-home.org
  4. */
  5. if (file_exists(CACHE_PATH . $file_name)){
  6. //$this->logger->error('file realpath:'.realpath(CACHE_PATH . $file_name));
  7. header( 'Pragma: public' );
  8. header( 'Expires: 0' );
  9. header( 'Content-Encoding: none' );
  10. header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
  11. header( 'Cache-Control: public' );
  12. header( 'Content-Type: application/vnd.ms-excel');
  13. header( 'Content-Description: File Transfer' );
  14. header( 'Content-Disposition: attachment; filename=' . $file_name );
  15. header( 'Content-Transfer-Encoding: binary' );
  16. header( 'Content-Length: ' . filesize ( CACHE_PATH . $file_name ) );
  17. readfile ( CACHE_PATH . $file_name );
  18. } else {
  19. $this->logger->error('export model :'.$id.' 错误:未生产文件');
  20. echo '<script>alert('export error, file not exists!')</script>';
  21. }
复制代码

>>> 您可能感兴趣的文章: 使用PHPExcel判别和格式化Excel中的日期格式的例子 phpExcel中文帮助手册(知识点) phpexcel快速开发指南(不错) phpexcel导入excel到数据库的代码 phpexcel导出数据的实例代码 phpexcel类库实例 支持(excel2003 excel2007) PHPExcel读取excel文件的例子 phpexcel导出excel的经典实例 phpExcel类的使用方法分享 PHPExcel常用方法举例 phpExcel实现的excel操作类



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template