No file download when using Excel2007 with save('php://output')

Topics: Developer Forum, Project Management Forum, User Forum
Apr 1, 2015 at 10:21 AM
Edited Apr 1, 2015 at 10:22 AM
Hi all,

I had an issue trying to generate a downloadable Excel2007 formatted file using PHPExcel 1.8.0.
The download was offered correctly when I developed it on my home WAMP server, but when I transfered my project to my live (hosted) website, I only got an empty page and no download.

The final part of the script contains:

$filename = "Myfile.xlsx";
header("Content-disposition: attachment; filename=\"".$filename."\"");
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate');
header('Pragma: public');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');

By investigating the issue I found out the "save('php://output');" part didn't return a correct temp dir for the temporary file to be created. In my situation it doesn't have anything to do with "write permissions", but with sys_get_temp_dir() not reurning the correct directory for temporary files.

I have changed line 197 of "PHPEcel/Writer/Excel2007" from:
$pFilename = @tempnam(PHPExcel_Shared_File::sys_get_temp_dir(), 'phpxltmp');
$pFilename = @tempnam(ini_get('session.save_path'), 'phpxltmp');

My issue is resolved now and maybe this helps others too! :)