Jump to content

loop to find out how many pictures are in a folder ?


pooker

Recommended Posts

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';

?>

 

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';

?>

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
}
?>

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.