I built a simple action in symfony which generates a PDF-file via wkhtmltopdf and outputs it to the browser.
Here's the code:
$response = $this->getResponse();
$response->setContentType('application/pdf');
$response->setHttpHeader('Content-Disposition', "attachment; filename=filename.pdf");
$response->setHttpHeader('Content-Length', filesize($file));
$response->sendHttpHeaders();
$response->setContent(file_get_contents($file));
return sfView::NONE;
That works fine in my local development environment - my browser gets the headers as expected, showing the download-dialogue.
Now I updated my testing-environment, running Apache 2.2.9-10+lenny9 with PHP 5.3.5-0.dotdeb.0. If i call that URL now for the testing-environment, my browser don't get any custom set headers:
Date Mon, 07 Mar 2011 10:34:37 GMT
Server Apache
Keep-Alive timeout=15, max=100
Connection Keep-Alive
Transfer-Encoding chunked
If I set them manually via header() in my action, Firebug shows the headers as expected. Does anybody know what could be wrong? Is it a symfony bug, or a php or apache2 configuration issue? I don't get it. :-/
Thanks in advance!
The only difference that I have is:
Your problem is here:
Change this to:
edit update due to extra comments.
Since you are trying to download a pdf, you're approach the problem incorrectly. Do not use
sendContent()
. See below (this is a snippet from a production site I've written and has proven to work across all major browsers):Got the same problem. Just add double quotes (") around the filename
or