#1
  1. Full Access
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jun 2000
    Location
    London, UK
    Posts
    2,019
    Rep Power
    17
    OK, I have just set up a primitive type of file-tracking on my page in PHP, whereby every time someone loads a wallpaper from my site, it increases the number held in a text file by one. So say the wallpaper was called foo.jpg, it would add one to the value of foo.jpg.count So what I need is a PHP script which will get all the files which have the extension .count, and write their values into an HTML page, with the first part of the file name next to it. eg:

    foo.jpg 10
    f002.jpg 22

    and so on. I can format this to draw a kind of bar chart with the results using a table. etc. etc.

    Each wallpaper would have its own file, and the file contains nothing apart from a number: which is the number I need printed onto the page.

    Could someone please help me out with this as I don't know how!

    Thanks in advance,

    ------------------------------------------
    Alex
    (http://www.alex-greg.co.uk)
  2. #2
  3. No Profile Picture
    Robert_J_Sherman
    Guest
    Devshed Newbie (0 - 499 posts)
    Sounds to me like you might want to try taking a slightly adjusted approach.

    say, the image is actually served via a
    "counter" script.

    The link, instead of being to a specific image is sent to a PHP script, maybe something like this:

    viewit.php?img=foo.jpg

    inside viewit.php you would increase
    and write to your foo.jpg.count file increasing the images' hit count, by 1.

    To read that count, I would say a secondary
    script like readit.php?img=foo.jpg

    something that directs the reading file, to pull the count for the foo.jpg image.

    Not real sure how exactly I might approach it, but something to consider.

    ------------------
    SnR Graphics,
    Low Cost Hosting and Web Development.
  4. #3
  5. Full Access
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jun 2000
    Location
    London, UK
    Posts
    2,019
    Rep Power
    17
    Robert_J_Sherman,

    You're right about me passing the link to a PHP script, but with the stats thing I want to read ALL the counters onto one page. The counter files (which just contain a a number) all have the extension .count

    I want to read all these onto a new page. With the names of the image they relate to next to them.

    For example I might have counter files called foo.jpg.count (12) and foo2.jpg.count (33) and in the resulting stats page I want this printed out:

    foo.jpg 12
    foo2.jpg 33

    How's this done?

  6. #4
  7. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    Perth West Australia
    Posts
    757
    Rep Power
    15
    do you mean this?

    <html><body bgcolor="#ffffff">
    <?php
    $file = fopen("foo13.count", "r"); //open file for reading
    $rf = fread($file, 4096); // read 1 line
    fclose( $file );
    echo "foo13.jpg=$rf;"
    ?>
    </body></html>

    foo13.count containing 1 number on 1 line only.

    ? - it would be much better to have all the values contained in 1 file otherwise you are going to have to call fopen for each file , which gets expensive after a bit.

    ------------------
    Simon Wheeler
    FirePages -DHTML/PHP/MySQL
  8. #5
  9. Full Access
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jun 2000
    Location
    London, UK
    Posts
    2,019
    Rep Power
    17
    FirePages,

    Thanks for the info. How would I read all the files at once onto one page? You don't seem to understand what I am trying to achieve: I want to read all the .count files onto one page at once, so I can compare how many downloads each file has had. The reason I am using separate .count files is because it is then very easy to add new files to the list of ones that I want tracked: I just link to it with my viewing script, and a .count file is automatically created for the new file.

    I need a function that will open each of the .count files in the directory, one after another, and read their values, along with their corresponding names, onto a new page.

    Thanks and sorry if I seem rude

    Alex
    (http://www.alex-greg.co.uk)
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    13
    Rep Power
    0
    How about this:

    $DIR=opendir('your-dir-path');
    while ($file = readdir($DIR)) { // read files one by one
    if (eregi( "count$", $file){ // only select filename with 'count' at the end
    $fp = fopen("$file", "r");
    $count[] = fread($fp, 4096);
    $filename[] = eregi_replace(".count", "", $file); //get the image name. e.g.: change foo.jpg.count to foo.jpg
    fclose( $fp );
    }
    }
    closedir($DIR);
    // print out results
    $i=0;
    while ($filename[$i] && $count[$i]) {
    echo "$filiename[$i]: $count[$i]n";
    $i++;
    }
    I didn't run the script to test it, hope it works. Again, if you have 10 files, you need to open file 10 times. If you have 10,000 files, every visitor will open 10,000 files for viewing one page. Duh!

    Good luck,
    Jinn

    ------------------
    Stories OnLine
    http://www.stories-online.net/

    WARNING: adult stories!
  12. #7
  13. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    Perth West Australia
    Posts
    757
    Rep Power
    15
    I understand what you are trying to acheive Alex - My point was exactly as just made by jinn - if you have a 100 files you are going to have to open and read a hundred files for each page request! - cpu expensive ie:slow!

    And my answer answered your question - you just have to loop it x amout of times.

    Jinn showed you a way to do this.

    It is possible to compact all your info on to one txt file and read and write to it , but how many different file names are there - is it finite? or variable? - need this info to post any sort of useful reply.

    ------------------
    Simon Wheeler
    FirePages -DHTML/PHP/MySQL
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    35
    Rep Power
    15
    I am not sure php + text files is the best thing to be doing this with.

    You could certainly do it by:
    Iterating over the file to find the right line every time you want to update a count.

    Iterating over the file to output every line for viewing.

    But you are going to bog down the system and cause all kinds of consistency problems because this way is going to be **slow**.

    Do you have access to mysql? If you can, a small table recording img name and a count would be so much quicker and allow you to sort the output for viewing.

Similar Threads

  1. Reading Outlook's *.MSG files in VB
    By jbulbule in forum Visual Basic Programming
    Replies: 0
    Last Post: February 12th, 2004, 07:27 PM
  2. Replies: 0
    Last Post: February 8th, 2004, 11:11 PM
  3. Reading Linux/BSD config files
    By boyohboy17 in forum C Programming
    Replies: 1
    Last Post: February 2nd, 2004, 09:44 PM
  4. Syntax error reading reading files
    By Rizla in forum C Programming
    Replies: 2
    Last Post: February 2nd, 2004, 09:18 AM
  5. Reading files that has certain parrent at once
    By cgi_pro in forum Perl Programming
    Replies: 2
    Last Post: January 29th, 2004, 11:13 PM

IMN logo majestic logo threadwatch logo seochat tools logo