Created
September 20, 2016 14:20
-
-
Save chukShirley/bfd954b24e38c9301f37771e459fb818 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class GeneratePdfController extends AbstractActionController | |
{ | |
public function indexAction() | |
{ | |
$filename = '/path/to/myFile.pdf'; | |
$response = new Stream(); | |
$headers = new Headers(); | |
$headers | |
->addHeaderLine('Pragma', 'public') | |
->addHeaderLine('Cache-Control', 'must-revalidate, post-check=0, pre-check=0') | |
->addHeaderLine('Content-Type', 'application/pdf') | |
->addHeaderLine('Content-disposition', 'inline; filename="' . basename($filename) . '";') | |
->addHeaderLine('Content-Transfer-Encoding', 'binary') | |
->addHeaderLine('Content-Length', filesize($filename)) | |
->addHeaderLine('Accept-Ranges', 'bytes'); | |
$response->setHeaders($headers); | |
$response->setContentLength(filesize($filename)); | |
$response->setStream(fopen($filename, 'r')); | |
return $response; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment