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