On 18 Sep 2003 16:19:03 -0700, Joshua wrote:
Is there a way to set up Apache to invoke a PHP equest when a file (a
image for example) is downloaded?
Say, then, that
http://www.foo.com/downloads/app1.zip is downloaded, Id like to have
Apache in turn invoke a PHP script which may be used to write a log.
Thanks,
Joshua
There's a pretty easy trick to do this -- I do something like this so that
I can hear netChimes alerts on my computer when a file is downloaded. It
requires that you have mod_rewrite installed on Apache (every hosting
account I've owned did).
First create a .php file that will act as a medium to transfer the files.
Here's what I use (in the directory with the downloadable files), it could
probably be better but it's short and sweet:
<?
$f = $_GET["filename"];
// put your desired PHP code here, to run on the download
// make sure you don't 'echo' anything, because you need
// to send the 'header's below
if(is_file($f))
{
header("Content-type: application/octet-stream\n");
header("Content-disposition: attachment; filename=\"$f\"\n");
header("Content-transfer-encoding: binary\n");
header("Content-length: " . filesize($f) . "\n");
$fp=fopen($f, "r");
fpassthru($fp);
}
?>
Now you have to tweak the mod_rewrite. Add this to your .htaccess file in
the directory of the downloadable files:
RewriteEngine on
RewriteRule appz1.zip download.php?filename=appz1.zip [L]
And then just keep adding the RewriteRule lines for each file you want to
trigger that process. You could easily enough add another variable to send
to determine what code to run, etc.
david
--
It is of interest to note that while some dolphins are reported to have
learned English -- up to 50 words used in correct context -- no human being
has been reported to have learned dolphinese.
-- Carl Sagan
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----