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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.