468,290 Members | 2,040 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,290 developers. It's quick & easy.

Is there a way to set up Apache to invoke a PHP equest when a file (a image for example) is downloaded?

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
Jul 17 '05 #1
4 2303
"Joshua" <st********@adelphia.net> wrote in message
news:5d*************************@posting.google.co m...
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


Instead of running the script after the file was sent, you could just point
all of your links to a PHP script that writes a log, then sends the
requested file.

Something like
http://www.foo.com/download.php?app1.zip

Jul 17 '05 #2
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! =-----
Jul 17 '05 #3
Hello!

Optionally you can redirect 404 error to you php script by putting this line
into .htaccess file of yourdirectory:

ErrorDocument 404 /yourdirectoryl/yourscript.php

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

-
Kindest Regards,
Olexiy Merenkov
http://www.merenkov.com/olexiy
Jul 17 '05 #4
On Thu, 18 Sep 2003 18:19:03 -0500, Joshua created an award-winning crop
circle <5d*************************@posting.google.com> , which, when
translated into English, means this:
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


No, but it's possible to write your script so that
it writes the log entry before allowing the download.

Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by RajeevSekar | last post: by
4 posts views Thread by lichaoir | last post: by
3 posts views Thread by Bill H | last post: by
3 posts views Thread by =?Utf-8?B?Um9nZXIgTWFydGlu?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.