SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Non-Member
    Join Date
    Dec 2004
    Location
    London
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is it possible...

    I want to do something that I unfortunately think may be impossible.
    I am trying to get the amount of bandwidth used for a certain directory in awstats (from cpanel). I have spent three hours puzzling over this, and nothing works! Here is a sample of the extracted code (to show youin more detail)
    Code:
    /forums/posting.php 51 780440 0 0
    /adamf/foleymovie.wmv 49 301753482 27 18
    /fun/ 38 313982 5 22
    /adamf2/Mikey_Whipwreck_vs_Rey_Misterio.wmv 34 230653355 12 21
    /yellowcake/preindex.htm 33 185088 9 14
    /games/ 33 192312 7 4
    /forums/index.php 31 495897 1 3
    /rallia/Anthropoi%20Monaxoi.mp3 28 17890473 14 12
    /forums/ 27 523257 3 6
    /rallia/Matia%20Matakia%20Mou.mp3 22 26853132 13 9
    /php1.php 20 260785 1 1
    /yellowcake/v2.swf 19 48314 3 7
    /forums/profile.php 19 181346 0 0
    /thescript.php 18 4253 0 0
    /webhosting/ 16 121500 3 3
    /templates/template_1/index.htm 15 64455 1 1
    /templates/template_1.zip 14 4647404 2 7
    /templates/template_7/index.htm 2 26740 0 0
    /forums/faq.php 1 42020 0 0
    /forums/search.php 4 38088 0 1
    /forums/./././faq.php 1 42455 0 0
    /templates/template_5/index.htm 3 21708 0 1
    the second number after the file is what I am trying to get (that is the bandwidth in bytes). All I want to do is get the sum o all of the, for example, /template/ files bandwidth, and I am having a hell of a time trying. Anyone brilliant have any ideas?
    If anyone can help me, I would be very thankful

  2. #2
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Parry Sound, ON
    Posts
    725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks like you could explode() each line on the space, then add up all the $arr[2] 's

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2004
    Location
    San Diego, CA (USA)
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this:
    PHP Code:
    $data //RAW DATA  (such as the data you provided above)

    $chunks explode("\n"$data);
    foreach (
    $chunks as $chunk) {
         
    $subdata[] = explode(' '$chunk);
    }
    foreach (
    $subdata as $subdatachunk) {
         
    $bandwidth $bandwidth $subdatachunk[2];
         print 
    'File: '.$subdatachunk[0].'<br>Bandwidth: '.$subdatachunk[2].'<br>';

    that would print out each file and its bandwidth.

    EDIT: updated the code above, i didnt read that you wanted all the bandwidths added up

  4. #4
    Non-Member
    Join Date
    Dec 2004
    Location
    London
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow! Thanks a lot for that code! I can do the rest, thanks again!


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
  •