SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2000
    Location
    Sydney, Australia
    Posts
    65
    Mentioned
    0 Post(s)
    Tagged
    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,

    download.php?id=23

    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.

    Thanks
    Last edited by Ardi; Feb 10, 2001 at 01:59.
    http://www.myringtones.net (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
    Location
    Netherlands
    Posts
    1,356
    Mentioned
    0 Post(s)
    Tagged
    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.
    www.nyanko.ws - My web-, software- and game development company.
    www.mayaposch.com - My personal site and blog.

  3. #3
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    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: www.page.com/file.zip), it should simply stay at that exact page and present a popped-up "Save As" box.


Bookmarks

Posting Permissions

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