Announcement

Collapse
No announcement yet.

Counting images in several directories?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Counting images in several directories?

    Hi,

    I would like to have my page display "This site contains $number images."

    Here's my directory structure:

    /gallery/june/images/pic.jpg
    /gallery/june/images/picture.jpg
    /gallery/june/images/pics.jpg

    /gallery/july/images/pic1.jpg
    /gallery/july/images/picture3.jpg
    /gallery/july/images/pics5.jpg

    How do I spider through all directories below /gallery and get a total count of the number of *.jpg images while excluding a directory called "thumbnails"?

    Any suggestions?

    Thanks,

    Tim
    Five Star Review Script - Add reviews to your website!
    Mixed Martial Arts - Houston MMA Training
    Women's Self-Defense - Courses and DVDs available

  • #2
    ttt
    Five Star Review Script - Add reviews to your website!
    Mixed Martial Arts - Houston MMA Training
    Women's Self-Defense - Courses and DVDs available

    Comment


    • #3
      PHP Code:
      <?php
      set_time_limit
      (0);

      function 
      count_folder($base_folder) {
          global 
      $total_images;

          
      $dh dir($base_folder);
          while (
      $entry $dh->read()) {
              if (
      $entry != '.' and $entry != '..') {
                  if (
      is_dir($base_folder.'/'.$entry)) {
                      if (
      $entry != 'thumbnails') {
                          
      count_folder($base_folder.'/'.$entry);
                      }
                  } elseif (
      substr($entry, -3) == 'jpg') {
                      
      $total_images++;
                      
      ### REMOVE THE LINE BELOW TO NOT SHOW THE FILE NAMES ###
                      
      echo $total_images.". <a href=\"$base_folder/$entry\">$entry</a> (".filesize($base_folder.'/'.$entry)." bytes)\n";
                  }
              }
          }
          
      $dh->close();
      }

      $base_folder '.';
      $total_images 0;
      echo 
      '<pre>';

      count_folder($base_folder);
      echo 
      "<b><u>Total images: $total_images</u>.</b></pre>";

      ?>
      Last edited by Chen; Sun 1 Sep '02, 11:23pm.
      Chen Avinadav
      Better to remain silent and be thought a fool than to speak out and remove all doubt.

      גם אני מאוכזב מסיקור תחרות לתור מוטור של NRG הרשת ע"י מעריב

      Comment


      • #4
        Very cool Firefly. Right after I posted ttt, I found a solution, but yours seems much better...less code.

        Thanks a lot!

        Tim
        Five Star Review Script - Add reviews to your website!
        Mixed Martial Arts - Houston MMA Training
        Women's Self-Defense - Courses and DVDs available

        Comment


        • #5
          You're welcome.
          Chen Avinadav
          Better to remain silent and be thought a fool than to speak out and remove all doubt.

          גם אני מאוכזב מסיקור תחרות לתור מוטור של NRG הרשת ע"י מעריב

          Comment


          • #6
            what does TTT mean anyway, never did find that out

            Comment


            • #7
              To The Top
              Hungry ?

              Comment


              • #8
                you mean like *bump*?

                Comment

                widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                Working...
                X