Search code examples
symfonyresponse

Symfony 2 attachment response file name


I have this code:

        $response = $excelService->getResponse(); // create response for excel object bundle
        $response->headers->set('Content-Type', 'text/vnd.ms-excel; charset=utf-8');
        $response->headers->set('Content-Disposition', 'attachment; filename='.basename('filename.xls'));
        $response->headers->set('Pragma', 'public');
        $response->headers->set('Cache-Control', 'maxage=1');
        $response->sendHeaders();
        return $response;

And when I click to download this file to my disk it's name is: filename.xls, attachment how can I remove this 'attachment' from my file name?


Solution

  • You need to remove $response->sendHeaders();