Skip to content

Instantly share code, notes, and snippets.

@vielhuber
Created September 20, 2023 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vielhuber/7d03a136a492fd338bedb3f44475e501 to your computer and use it in GitHub Desktop.
Save vielhuber/7d03a136a492fd338bedb3f44475e501 to your computer and use it in GitHub Desktop.
stream output pdf directly to browser #php
<?php
$file_abspath = '/foo/bar/baz.pdf';
$file_pseudoname = 'bazzz.pdf';
$content = file_get_contents($file_abspath);
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="' . $file_pseudoname . '"');
header('Content-Length: ' . strlen($file_abspath));
header('Cache-Control: private, max-age=0, must-revalidate');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
die($file_abspath);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment