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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joshua

    #1

    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
  • Jason

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

    "Joshua" <starbuxman@ade lphia.net> wrote in message
    news:5ddafe2.03 09181519.49a4bc 71@posting.goog le.com...[color=blue]
    > 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
    >[/color]

    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




    Comment

    • D K Woods

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

      On 18 Sep 2003 16:19:03 -0700, Joshua wrote:
      [color=blue]
      > 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[/color]

      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! =-----

      Comment

      • Olexiy Merenkov

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

        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

        [color=blue]
        > 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[/color]


        -
        Kindest Regards,
        Olexiy Merenkov



        Comment

        • Gary Petersen

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

          On Thu, 18 Sep 2003 18:19:03 -0500, Joshua created an award-winning crop
          circle <5ddafe2.030918 1519.49a4bc71@p osting.google.c om>, which, when
          translated into English, means this:
          [color=blue]
          > 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[/color]

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

          Comment

          Working...