Page 1 of 1

noob - number of files in a directory and making an array

Posted: Wed Oct 22, 2003 3:35 am
by MrBojangles
Hi

I've been struggling with this and thought i'd turn to you for help

I've got a folder full of images numbered image1, image2 etc and a php file in the same folder that's supposed to count the number of files and return a variable - here's what i've tried but doesn't work

Code: Select all

$handle=opendir('.'); 
	$strSought = "jpg"; 
	$numImages=0;  
	while ($pic = readdir($handle)) 
	{ 
		if ($strSought == substr($pic, -3)) 
		{ 
		    $numImages = $numImages + 1; 
		} 
	} 
	closedir($handle);
what should i do to make it function ?
and also, at the moment i get the images to change by incrementing the number after the string "image" in the filename and then refreshing the page.
However, if i remove an image from the folder the sequence is broken and doesn't work ...
so, what method do i need to use to make an array from the names of all the files in the folder? I guess it's quite simple but my attempts have all failed ....

any help you can give will be received with gratitude

thanks

Posted: Wed Oct 22, 2003 4:16 am
by volka
take a look at viewtopic.php?t=13806

Posted: Wed Oct 22, 2003 5:03 am
by MrBojangles
ok - i'll have a look

thanks