Results 1 to 2 of 2

Thread: How to show amount of downloads

  1. #1
    Join Date
    Apr 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to show amount of downloads

    I want to show the amount of times an image has been viewed, ive tried this:

    <script src="http://fastwebcounter.com/secure.php?s=IMAGE></script>
    But it doesn't seem to work, it shows the amount of times that page has been viewed. Any ideas of scripts I could use?

    Blaine

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    This needs to be done with a server-side language such as PHP. In PHP, the code would run as follows:
    PHP Code:
    <?php
    // clickcounter.inc.php
    $newline "\n"// Newline symbol for the server.  Likely values are "\n" for *n?x or "\r\n" for Windows.
    $filename "clickcount.dat"// Name of the file in which to store number of clicks.

    // Function to get the number of registrants.
    function getClicks() {
      global 
    $filename$newline;
      return 
    file_exists($filename) ? implode(file($filename), $newline) + 0;
    }

    // Function to increment the number of registrants.
    function incClicks() {
      global 
    $filename$newline;
      
    $clickcount getClicks();
      
    $clickcount++;
      
    $file fopen($filename"w");
      
    fputs($file$clickcount);
      
    fclose($file);
    }
    ?>
    PHP Code:
    <!-- Top of the page on which to display the number of clicks: -->
    <?php include("clickcounter.inc.php"); ?>
    <!-- Where you want to display the number of views: -->
    <p>Number of views: <?php echo(getClicks()); ?></p>
    PHP Code:
    <?php
      
    // This page instead of the image:
      
    include("clickcounter.inc.php");
      
    $image "myimage.png";
      
    header("Content-Type: " mime_content_type($image));
      
    incClicks();
      
    readfile($image);
    ?>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •