Serve PDF file with PHP


/ Published in: PHP
Save to your folder(s)

Quick basic way to serve a string or a file through PHP


Copy this code and paste it in your HTML
  1. // pdfString is the *contents* of a file.
  2. // to serve a file that exists on the file system, use readfile() instead of print $pdfString
  3.  
  4. header('Content-Description: File Transfer');
  5. header('Content-Type: application/pdf');
  6. header('Content-Length: ' . strlen($pdfString));
  7. header('Content-Disposition: attachment; filename=' . 'pdf_dynamic.pdf');
  8. print $pdfString;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.