Can I use the PHP code below if the PDF file is not on my server but on a different server with a different IP? If not, what’s the best replacement?
This code fragment was taken from this PHP tutorial: http://www.devshed.com/c/a/PHP/Simple-and-Secure-PHP-Download-Script-with-Limits-Tutorial/
//Define the content type and show force download attachment dialog
header("Content-type:application/pdf");
header('Content-Disposition: attachment; filename="http://www.yourdomain.com/ebookfordownloads/ebook.pdf"');
//Stream the PDF file for downloading using PHP readfile function
//The readfile is using absolute server path
//You can determine this path by uploading a php script to the folder containing the download material.
/*
<?php
echo $_SERVER['SCRIPT_FILENAME'];
?>
*/
readfile("/your/absolute/server/path/html/ebookfordownloads/ebook.pdf");
Yes, that would be possible, depending on your servers settings. It will have to allow connections to other servers (
allow_url_fopenshould be true) to do so. Other than that, you’re golden 😉