PHP htaccess file serve script

search this blog for the “htaccess” file contents to put in a directory, then use this to serve up pdf files securely from said directory:

file serve php script:

first check Zend permissions…logged in, permissions granted, user active, expirations, etc…..

$file = “path/path/” . $_GET[‘file’];
//$file = “Broker_Admin/Materials/Course.pdf”;
header(‘Content-type: application/pdf’);
header(“Content-Disposition: inline; filename=”.$file);
/*header(“Content-Disposition: attachment; filename=”.$file);*/
header(‘Last-Modified: ‘.gmdate(‘D, d M Y H:i:s’) . ‘ GMT’);
header(‘Cache-Control: no-store, no-cache, must-revalidate’);
header(‘Cache-Control: pre-check=0, post-check=0, max-age=0’);
header(‘Pragma: anytextexeptno-cache’, true);
header(‘Cache-control: private’);
header(‘Expires: 0’);

then from wherever I want to call it I call this script and pass in the file wanted.

like this:

<a href=”file_serve.php?file=Test.pdf”>Download the Test file here</a>

File is NOT accessible directly, or via this script since it first checks visitor’s SESSIONS, ZEND Permissions, that variables passed to it are set, etc. and so on…

Comments are closed.