Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use PHP to count images in specific subdirectories

Tags:

php

I've got images stored in a directory structure a bit like this:

  • images
    • foo
      • thumb
        • awefawef.jpg
        • dtyhtyh.jpg
      • full
        • awefawef.jpg
        • dtyhtyh.jpg
        • eriguherg.jpg
    • bar
      • thumb
        • erg.jpg
      • full
        • erg.jpg
        • tyjhr5g.jpg
    • some_other_dir
    • etc ...

(Note: There won't always be the same number of images in a "thumb" directory as in it's neighbouring "full" one.)

So: I need to use PHP to count the total number of images in all of the "full" directories.

I'm sure I could find a way to do this by getting a list of all subdirectories of "images", then cycling through them and counting the images in each one's "full" folder. But as there are going to be thousands of directories with hundreds of images in each folder, I'm looking for the most efficient solution possible - this is going to need to be done pretty often by the site.

What's the most efficient approach here?

like image 813
Frank Harrison Avatar asked Aug 02 '12 17:08

Frank Harrison


1 Answers

This would work in the situation you've outlined:

$imagecount = count(glob("images/*/full/*.jpg"));
like image 130
Niet the Dark Absol Avatar answered Sep 26 '22 03:09

Niet the Dark Absol