2levelsabove Posted March 4, 2008 Share Posted March 4, 2008 How can one find out in PHP the number of jpeg files in a folder ? Thanks Link to comment https://forums.phpfreaks.com/topic/94343-how-to-get-the-number-of-jpeg-files-on-a-folder/ Share on other sites More sharing options...
schilly Posted March 4, 2008 Share Posted March 4, 2008 Use opendir() to get the handle of the directory then use a while with readdir() to get each filename. Check to see if the filename has the jpg extension then increment a counter. Link to comment https://forums.phpfreaks.com/topic/94343-how-to-get-the-number-of-jpeg-files-on-a-folder/#findComment-483198 Share on other sites More sharing options...
chocopi Posted March 4, 2008 Share Posted March 4, 2008 Just use something along the lines of: <?php $path = "./images/"; $dh = opendir($path); $NumOfFiles = 0; while ($file = readdir($dh)) { if(eregi("(.*\.jpg)",$file)) { $NumOfFiles++; } } closedir($dh); echo $NumOfFiles; ?> It's untested but it should work, if my memory serves haven't done php in a while. ~ Chocopi Link to comment https://forums.phpfreaks.com/topic/94343-how-to-get-the-number-of-jpeg-files-on-a-folder/#findComment-483222 Share on other sites More sharing options...
KrisNz Posted March 4, 2008 Share Posted March 4, 2008 There's also the glob() function http://nz2.php.net/glob Link to comment https://forums.phpfreaks.com/topic/94343-how-to-get-the-number-of-jpeg-files-on-a-folder/#findComment-483369 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.