Unable to open file generated with PHPExcel

1

Why does downloading my file as Excel from a PHP page give me an error that it can not be opened or the extension is not valid? Will this part of the code where I give it name and extension have to do?

<?php 
function activeErrorReporting()
{
  error_reporting(E_ALL);
  ini_set('display_errors', TRUE);
  ini_set('display_startup_errors', TRUE);
  date_default_timezone_set('Europe/London');
}

function noCli()
{
  if (PHP_SAPI == 'cli')
    die('This example should only be run from a Web Browser');
}

function getHeaders()
{
  // Redirect output to a client’s web browser (Excel5)
  header('Content-Type: application/vnd.ms-excel');
  header('Content-Disposition: attachment;filename="01simple.xlsx"');
  header('Cache-Control: max-age=0');
  // If you're serving to IE 9, then the following may be needed
  header('Cache-Control: max-age=1');

  // If you're serving to IE over SSL, then the following may be needed
  header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
  header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  header ('Pragma: public'); // HTTP/1.0
}
    
asked by alvin 21.07.2017 в 01:26
source

1 answer

1

You have to remove the quotes from the file name, you can try the following headers, although if the file is badly formed, it will send you an error when opening it.

header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-Disposition: attachment; filename=01simple.xls");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);

It would be necessary to review the file with a text editor to confirm that PHP is not generating any type of Output as errors or similar within the file.

    
answered by 21.07.2017 в 06:30