You need to use the php file to submit the file where the PDF files are stored in the NON PUBLIC folder.
For example, place your pdf files in a public directory, say: / home / pdfs /
And your PHP script in the public directory is accessable, say: / home / public_html /
Inside the script in the public directory, put:
if (isset($_GET('password')) { die('wrong password'); } if ($_GET['password'] != 'mypass') { die('wrong password'); } $file="/home/pdfs/test.pdf"; header("Pragma: public"); header('Content-disposition: attachment; filename='.$file); header("Content-type: ".mime_content_type($file)); header('Content-Transfer-Encoding: binary'); ob_clean(); flush(); readfile($file);
Use GET values to determine the file you are downloading, but for better security, allow .pdf extensions, delete all other periods and slashes so that they cannot move through your server directories and receive important security files containing passwords, etc. !!! To be even safer, still name your pdf files with the characters az 0-9 and - or _
And then when you want to download the file, return the URL in the script above and make sure the pdf file exists in the public directory.
source share