Solve the problem that php cannot be opened when downloading excel files

Source: Internet
Author: User
Solve the problem that php cannot be opened when downloading excel files

  1. /**
  2. * Php code for 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.' error: file not produced ');
  20. Echo 'script alert (\ 'export error, file not exists! \ ') Script';
  21. }

>>> Articles you may be interested in: examples of using PHPExcel to identify and format the date format in Excel: phpExcel Chinese help Manual (Knowledge Point) phpexcel quick Development Guide (good) phpexcel database import code phpexcel data export instance code phpexcel class library instance support (excel2003 excel2007) examples of PHPExcel reading excel files phpexcel exporting the use of the phpExcel class of a classic excel instance share PHPExcel common methods examples of excel operations implemented by phpExcel

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.