PHP zend framework

HTTP response headers in Zend Framework

I needed to display a Zend Framework generated PDF using the browser plugins and after a bit of looking around it turns out that some headers need to be set in order to achieve that.

     ->setHeader('Content-Disposition', 'inline; filename=invoice.pdf')
     ->setHeader('Content-type', 'application/x-pdf');

If you’d want to automatically download the PDF instead of displaying it using the browser plugins, you need to change the ‘Content-Disposition’ as follows:

     ->setHeader('Content-Disposition', 'attachment; filename=invoice.pdf')
     ->setHeader('Content-type', 'application/x-pdf');

1 reply on “HTTP response headers in Zend Framework”

You’ll probably want to set the 3rd argument to setHeader to true:
->setHeader(‘Content-Disposition’, ‘attachment; filename=invoice.pdf’, true)

This will avoid the duplicate headers error which new versions of Chrome will throw.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.