472,980 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,980 software developers and data experts.

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 2480
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: chad | last post by:
let's say I'm transferring a large file like 100MB over to a folder. The program detects when the file arrives. However, I can't figure out how to know when the file is totally transferred over....
0
by: RajeevSekar | last post by:
Hi Experts, I am trying to invoke a batch(reside in my local machine) file from asp.net using System.diagnostics.process.start("path\filename") method, it is working fine, but when i try to...
6
by: fredo | last post by:
A few days ago, Jim answered (THANK YOU, Jim) my question about how to make an image pop up when an image link is hovered. That discussion is here: ...
2
by: bizt | last post by:
Hi, Is it possible to obtain the width/ height of an image when that image is dyanically created using a PHP script and passing GET attributes. For example: <img...
3
by: ajaymohank | last post by:
hello everyone..... i am ajay and i am new to php. in my project i have an option to invoke a bat file by passing parrameters and to diplay the result. i tried this code but my page got hung or...
4
by: lichaoir | last post by:
Hmm... What I really mean is... I want to write a program to monitor file downloading. I want to be notified when a file has been downloaded, so I can write a record into database. How should I...
3
by: Bill H | last post by:
I have written many programs for file / image upload over the years in perl, but know that I am working more in php I find I need to be able to do it in php now. I was gonna just do a google serach...
3
by: =?Utf-8?B?Um9nZXIgTWFydGlu?= | last post by:
Note: My apologies for repeating this post from last week, but my nospam alias and profile account were incorrect. I think I have fixed this, so hopefully this post will trigger MS into a response...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.