faqts : Computers : Programming : Languages : PHP : Common Problems : Code Execution

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

22 of 40 people (55%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

How can I download a pdf file using php

Jun 19th, 2004 11:17
Philip Olson, Sbongile Maseko, http://www.php.net/header


You may force a PDF file by sending proper HTTP headers to the users 
client (such as their browser) so for example let's say we have a file 
named original.pdf and we want to force the user to download it and for 
fun we'll rename it downloaded.pdf:
<?php
 // We'll be outputting a PDF
 header('Content-type: application/pdf');
 // It will be called downloaded.pdf
 header('Content-Disposition: attachment; filename="downloaded.pdf"');
 // The PDF source is in original.pdf
 readfile('original.pdf');
?>
See also the PHP manual for header() here:
  http://www.php.net/header