473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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 2500
"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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.