Problems generating downloadable files

Feb 16, 2010 at 4:03 PM

Hi every:

I'm using PHPExcel from Symfony using sfPHPExcel plugin. I need the generated file can be downloaded by the user and for this I have included this code

$this->getResponse()->setContentType('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
$this->getResponse()->setHttpHeader('Content-Disposition','attachment;filename="'.$filename.'.xlsx');
$this->getResponse()->setHttpHeader('Cache-Control','max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
$objWriter->setOffice2003Compatibility(true);
$objWriter->save('php://output');

When I run the function I get a stack of strange characters and not let me download anything, anyone know where it fails?

Greetings and thanks in advance

Coordinator
Feb 16, 2010 at 5:53 PM

From the description of the output, it looks as though the http headers are being ignored

I don't know Symfony, although there's a couple of threads about using PHPExcel with Symfony here on the board.

 

I always include

Content-Transfer-Encoding: binary

among my http headers

Feb 16, 2010 at 7:04 PM

Niet, it don't works

Developer
Feb 16, 2010 at 11:16 PM

I have no experience with Symfony either, but are you checking that headers are set as expected?

You can for example use the Live HTTP Headers add-on for Firefox to check.

https://addons.mozilla.org/en-US/firefox/addon/3829