Filters are unnecessary for such a simple thing. What you want to do is, ideally, to use a rewrite rule along the lines of
RewriteRule ^/path/to/folder/(.*)$ /path/to/script/script.php?file=$1
So if the files you want to restrict access to are in /myfiles/ and your script is in /myscripts/accessctl.php, something like
RewriteRule ^/myfiles/(.*)$ /myscripts/accessctl.php?file=$1
should do the trick. That's for Apache, other servers will vary. You can drop it in a .htaccess file if that's enabled. But this will (if I haven't screwed up the black magic of RewriteRules) make all attempts to access your files from the Internet be sent to this script instead.
Your script might look something like this:
PHP Code:
<?php
// This is the path to my files from this script
define( 'DIRPATH', '../myfiles/' );
// Remove anything including a slash before the filename, to avoid access
// to arbitrary files (note that as written this will prevent access to
// subdirectories too)
$filename = preg_replace( '!^.*/!', '$1', $_REQUEST['file'] );
if( $_REQUEST['name'] ) {
$fileexists = file_exists( DIRPATH . $filename );
// Write out the name to your records and provide the file . . . this I leave
// as an exercise because I've gotten bored of coding
} else {
// Present a handy little form
$encodedfilename = urlencode($filename);
// The name of this file. Probably a better way to get it somehow
$scriptname = preg_replace( '!^.*/!', '$1', __FILE__ );
echo <<< HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" lang="en">
<head>
<title>Confirmation form</title>
</head>
<body>
<p>Please enter your name for my records.</p>
<form action="$scriptname?file=$encodedfilename" method="get">
<input type="text" name="name" value="Your name here" tabindex="1" />
</form>
</body>
</html>
HTML;
}
I haven't tested this at all, so it may fail horribly, but perhaps I've given you a starting point. Good luck, and feel free to ask any further questions.