php reading directory problem
Posted: Tue Sep 19, 2006 5:03 pm
hi all..
I am reading all image files by this code.
the problem is i am not getting the file names sorted in fnarray[]. when i print it i get like 50.jpg then 35.jpg then 1.jpg then 32.jpg then 26.jpg.. etc but i need to get like 1.jpg, 2.jpg, 3.jpg.. etc.. in ascending order while reading.. What should i do ?
I am reading all image files by this code.
Code: Select all
$dir = "images/";
$jpgext = ".jpg";
$dh = opendir($dir);
while($filename = readdir($dh))
{
$filepath = $dir.$filename;
if(is_file($filepath) and ereg("\.jpg$",$filename))
{
$gallery[] = $filepath;
$fnarray[] = $filename;
$count++;
}
}