My script is the following:
<?php
header("Content-type:application/pdf");
// It will be called downloaded.pdf
header("Content-Disposition:attachment;filename='test.pdf'");
// The PDF source is in original.pdf
readfile("www.example.com/test.pdf");
?>
Now if I change readfile to say:
// The PDF source is in original.pdf
readfile("test.pdf");
It works fine, if however I specify and absolute URL, readfile("www.example.com/test.pdf");
the PDF does not open up. The above only seems to work locally.
Does anybody know why absolute url’s are not working? Cheers
Solution:
// The PDF source is in original.pdf
readfile($_SERVER['DOCUMENT_ROOT']."/test.pdf");
This function only works with absolute paths, not urls.
http://allow_url_fopensettings!.
A smarter approach would be to store/cache the remote file localy, so you don’t have to download it every time. And it would take the load off the target site.