SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2000
    Sydney, Australia
    0 Post(s)
    0 Thread(s)

    Downlaod Counter

    Hi, I'd like to set up a script that would let the user download a file on my site.

    so the link would like like,


    the catch is, i don't want the user to be redirected to the next page, i want the user to be able to download the zip file as soon as that link is clicked.

    I also want to use php so i can eep track on which are the most popular file downloads.

    How would I be able to do this? Im not quite sure on how to do it using this method.

    Last edited by Ardi; Feb 10, 2001 at 01:59. (down again) - Free Ringtones for your Nokia and Ericsson GSM phone : brought to you by The Ringtone Factory

  2. #2
    Fluffy Kitten Programmer~ Elledan's Avatar
    Join Date
    Jun 2000
    0 Post(s)
    0 Thread(s)
    RE: Starting download from the same page

    This isn't possible from the same page. A possibility would be to open a small new window in which you load the download.php page. After the download has started, this window can be closed.

    RE: Counting the number of downloads

    A way to accomplish this is by using an (my/postgre)SQL database in which you update one table every time a file is being downloaded.

    Like this:
    > The new window opens, 'download.php' is being loaded
    > On the server, the ID of the file which is being downloaded gets passed to a piece of code which does the following:
    *Get the value of the column 'totaldownloads' WHERE ID='$id' and increase it by 1 (i.e. $var++)
    *Update the column 'totaldownloads' WHERE ID='$id' and insert the updated value in the right cel


    That's about it. If you've any questions, don't hesitate to ask them. - My web-, software- and game development company. - My personal site and blog.

  3. #3
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Pittsburgh, PA, USA
    0 Post(s)
    0 Thread(s)
    I'd go about it a different way - I'd create a table to store all instances of downloads. Everytime the page is loaded, an SQL query is executed logging the user's IP address, time of day, and, of course, an ID number pertaining to the file.

    That way, when you want the number of total downloads, a simple SELECT COUNT(fileid) will do the trick, and you have more data than you'll ever need.

    I learned this from Kevin the hard way - incrementing like that can be risky business if site traffic increases.

    As for the redirection: if you redirection exactly to the file (IE:, it should simply stay at that exact page and present a popped-up "Save As" box.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts