473,815 Members | 2,987 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2527
"Joshua" <st********@ade lphia.net> wrote in message
news:5d******** *************** **@posting.goog le.com...
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?fi lename=appz1.zi p [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************ *************@p osting.google.c om>, 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
2053
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. One unsuccessful method is to... dim fi as new fileinfo(newfile) fi.length returns the supposed size of the file. But it correctly
0
1265
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 invoke a batch file reside in my server machine through the same System.diagnostics.process("path\filename") method, the system throws "The system cannot find the file specified " Exception can anyone help me to invoke batch file in remote machine
6
5863
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: http://groups.google.com/group/comp.infosystems.www.authoring.stylesheets/browse_thread/thread/e9a21d6f46ac7168/40b2599e189fce58?hl=en#40b2599e189fce58 Jim's stylesheet made everything work beautifully in FF; and in IE, too. But when I changed his stylesheet to display thumbnails...
2
3537
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 src="images/showImage.php?image_id=5" /> My images are created from images stored on the server, their paths stored on in database table and retrieved using the GET image_id and
3
4500
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 display nothing... exec("c:\collabland\collabland.bat $distcode $tlkcode $villacod $block $svno"); here by passing this parameters to collabland.bat, a sketch will be generated based on the parameters and it should be displayed. when i type in...
4
1714
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 implement this? My colleague has written a program, but is has some problem: ------------------------------------------------------------------------------------------------------------------------------------------- Response.BufferOutput =...
3
1904
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 on how it is done in php, but I though it would be wiser to ask the members of this group how they accomplish it instead of relying on the top most hits on a search that I may be wording wrong. So, can anyone point me to some trusted docs,...
3
689
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 per their MSDN policy. -------------------- I have a web site under .NET 2.0 that renders videos using the Silverlight media player. The web page looks like this: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="video2.aspx.cs"
0
10672
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10408
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10428
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10145
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9226
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5710
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3030
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.