0

File format and extension doesn't match error occurs in excel .xls using readfile(). But, output excel file in app/tmp/excel/ is not a problem. Also using chrome browser.

my code is below.

$filename = date('YmdHis').'.xls';
$upload = realpath( TMP );
$upload .= DS . 'excel' . DS;

$objWrite = new PHPExcel_Writer_Excel5($PHPExcel);
$objWrite->save($downloadPath);

header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Last-Modified: '.gmdate ('D, d M Y H:i:s', filemtime ($fileName)).' GMT');
header('Cache-Control: private',false);
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="'.basename($fileName).'"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.filesize($fileName)); // provide file size
header('Connection: close');
readfile($fileName);
arcs
  • 51
  • 1
  • 8
  • `$downloadPath != $filename`!? – ndm Nov 21 '14 at 10:26
  • Sorry, $downloadPath == $filename. – arcs Nov 21 '14 at 11:27
  • In that case I'd suggest to compare two files, (a none working) one that was downloaded and (a working) one what was written to the temp folder, this might give a hint where things go wrong. **http://stackoverflow.com/questions/6877238/what-is-the-windows-equivalent-of-the-diff-command** | **http://apple.stackexchange.com/questions/10099/what-file-comparison-tool-can-i-use-under-os-x** – ndm Nov 21 '14 at 11:46

0 Answers0