pooker Posted June 19, 2008 Share Posted June 19, 2008 How would I go about doing this ? I basically want it to find out how many images are in a folder, is this how I would do it? all of the images are named like B-1 etc, etc $number = 1; while(http://url.com/folder/B-$number.jpg = true) { $number=$number + 1; } echo 'there are' . $number 'in this folder'; ?> Link to comment https://forums.phpfreaks.com/topic/110848-loop-to-find-out-how-many-pictures-are-in-a-folder/ Share on other sites More sharing options...
bluejay002 Posted June 19, 2008 Share Posted June 19, 2008 you can use scandir() to scan the files in the files. then you can check the file types using filetype(). Link to comment https://forums.phpfreaks.com/topic/110848-loop-to-find-out-how-many-pictures-are-in-a-folder/#findComment-568729 Share on other sites More sharing options...
trq Posted June 19, 2008 Share Posted June 19, 2008 Also, it can't be used on a remote directory, but locally its simple.... <?php echo count(glob('/path/to/images/B*jpg')); ?> Link to comment https://forums.phpfreaks.com/topic/110848-loop-to-find-out-how-many-pictures-are-in-a-folder/#findComment-568733 Share on other sites More sharing options...
xtopolis Posted June 19, 2008 Share Posted June 19, 2008 Further supporting current suggestions, multiple image types: <?php echo count(glob("{*.jpg,*.JPG,*.png,*.PNG,*.gif,*.GIF}", GLOB_BRACE)); ?> From this thread. Link to comment https://forums.phpfreaks.com/topic/110848-loop-to-find-out-how-many-pictures-are-in-a-folder/#findComment-568744 Share on other sites More sharing options...
pooker Posted June 19, 2008 Author Share Posted June 19, 2008 Thanks guys, no matter which way I set it up it still sees it as zero though any reason? Here is what I used , I tried with the glob and without, the reason I did without is because each of these directories just stores images. <?php $dir = './bleach/chapter1/'; $total = count($dir) ; echo 'There are ' . $total . ' images'; ?> Link to comment https://forums.phpfreaks.com/topic/110848-loop-to-find-out-how-many-pictures-are-in-a-folder/#findComment-568746 Share on other sites More sharing options...
trq Posted June 19, 2008 Share Posted June 19, 2008 Look at the replies, then look again at your code. Link to comment https://forums.phpfreaks.com/topic/110848-loop-to-find-out-how-many-pictures-are-in-a-folder/#findComment-568749 Share on other sites More sharing options...
bluejay002 Posted June 19, 2008 Share Posted June 19, 2008 i suppose that should be: $total = count(scandir($dir)); // returns the number of files instead of: $total = count($dir); // returns 1 or alternatively, here is a little mod of the previous ones <?php $dir = "./images/"; // replace this with the path where the images are stored foreach (glob("{$dir*.jpg,$dir*.JPG,$dir*.png,$dir*.PNG,$dir*.gif,$dir*.GIF}", GLOB_BRACE) as $filename) { // do whatever you want here } ?> Link to comment https://forums.phpfreaks.com/topic/110848-loop-to-find-out-how-many-pictures-are-in-a-folder/#findComment-568835 Share on other sites More sharing options...
bluejay002 Posted June 19, 2008 Share Posted June 19, 2008 ooops... replace: glob("{$dir*.jpg,$dir*.JPG,$dir*.png,$dir*.PNG,$dir*.gif,$dir*.GIF}", GLOB_BRACE) with: glob("{".$dir."*.jpg,".$dir."*.JPG,".$dir."*.png,".$dir."*.PNG,".$dir."*.gif,".$dir."*.GIF}", GLOB_BRACE) Link to comment https://forums.phpfreaks.com/topic/110848-loop-to-find-out-how-many-pictures-are-in-a-folder/#findComment-568867 Share on other sites More sharing options...
pooker Posted June 19, 2008 Author Share Posted June 19, 2008 hey thanks I actually got it working earlier, here is my new thread about trying to update a variable to change a picture with onclick , think you can take a look at it? Alax, etc really confuses me http://www.phpfreaks.com/forums/index.php/topic,202630.0.html Link to comment https://forums.phpfreaks.com/topic/110848-loop-to-find-out-how-many-pictures-are-in-a-folder/#findComment-568878 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.