Number of Downloads

Discussion in 'Programming' started by LilSniper, Jun 13, 2008.

  1. #1
    hi, the only language I know is HTML but I can read php and some other stuff. is there a particular code or script to use to get the number of times a file has been downloaded....thanks!
     
    LilSniper, Jun 13, 2008 IP
  2. ToddMicheau

    ToddMicheau Active Member

    Messages:
    183
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    58
    #2
    You will need php or some other server side lang and sql, basically it just numerically increases a column in a database. A google search for "download count script" comes up with tons of them, like: http://www.phpjunkyard.com/php-click-counter.php.

    You'll need php installed as well as mysql. Hope that helps =]
     
    ToddMicheau, Jun 13, 2008 IP
  3. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #3
    You can actually make it store this "number of downloads" in a file

    for example

    the download link will be

    www.mysite.com/download.php

    and the php code on that download.php will be
    <?php
    $count = file_get_contents("counter.txt");
    $new = (int)$count + 1;
    file_put_contents("counter.txt",$new);
    header('Location: http://www.sitename.com/file.exe');
    ?>
    PHP:
    so every time somebody goes to the download.php, the counter goes up one, and they then download the file

    then you just use this code to display your counter

    <?php echo "Number of Downloads: " . file_get_contents("counter.txt"); ?>
    PHP:
    enjoy :)
     
    crath, Jun 13, 2008 IP