I would like to run a PHP code when a file on the web server is accessed (e.g. /../../somefile.pdf).
I need to display a disclaimer when a user access the website for the first time. I made this possible executing a PHP script every time a webpage is accessed but I don't know how to run the script when a file instead is accessed of a webpage. Is this possible?
Thank you!
When you want to track downloads, there are two ways:
<a href="/../../somefile.pdf">..</a>
try <a href="/download.php?file=/../../somefile.pdf">..</a>
RewriteRule ^download_directory/(.*)$ /download.php?file=$1 [L,QSA]
In your file, download.php you have two options again:
file
param, and use PHP to echo the output. (This method is insecure as the user may modify the path in the file
param and get a file he is not supposed to access.)header('Location: ' . $_GET['file']);