The Slim Framework support forum has moved to This Tender forum is no longer maintained or monitored.


Heinz Becker's Avatar

Heinz Becker

11 Feb, 2014 09:02 AM

I am trying to create an Excel file using PHPExcel in a slim controller and to output the result directly to the browser.
The excel gets created but when outputted to the browser I get a corrupted XLS file.
I tried to set the header information like this, but it sill does not work:
$app->response->headers->set('Pragma', 'public'); $app->response->headers->set('Expires', '0'); $app->response->headers->set('Cache-Control', 'must-revalidate, post-check=0, pre-check=0'); $app->response->headers->set('Content-Type', 'application/force-download'); $app->response->headers->set('Content-Type', 'application/octet-stream'); $app->response->headers->set('Content-Type', 'application/download'); $app->response->headers->set('Content-Disposition', 'attachment;filename=srl_statistic.xlsx'); $app->response->headers->set('Content-Transfer-Encoding', 'binary');

Any ideas how to solve this ?

  1. 1 Posted by Martin on 01 Oct, 2015 09:32 AM

    Martin's Avatar

    Year 2015: Has anyone an idea how to solve this? I have the same problem :(
    Any help would be appreciated.

  2. 2 Posted by Sylfel on 01 Oct, 2015 12:15 PM

    Sylfel's Avatar


    in an old application (in symfony 2) , i used :

            $response = $this->excelService->getResponse();
            $response->headers->set('Content-Type', 'text/; charset=utf-8');
            $response->headers->set('Content-Disposition', 'attachment;filename="'.$fileName.'.xls"');
            $response->headers->set('Pragma', 'public');
            $response->headers->set('Cache-Control', 'maxage=1');
            return $response;

    and it worked.
    Hope it will help you !


  3. 3 Posted by Martin Gross on 01 Oct, 2015 01:07 PM

    Martin Gross's Avatar

    Thank you very much. The error was quite crazy: after the ending of the php script „?>“ i had a blank which crashed the excel!

    Von: Sylfel [mailto:[email blocked]]
    Gesendet: Donnerstag, 1. Oktober 2015 14:16
    An: Martin Gross <[email blocked]>
    Betreff: Re: PHPExcel [Questions #1438]

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac