php reading directory problem

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
satheshf12000
Forum Commoner
Posts: 25
Joined: Mon Sep 04, 2006 5:38 pm

php reading directory problem

Post by satheshf12000 »

hi all..

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++;
}
}
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 ?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

1. look into using glob()
2. while looping through the directory, store the files in an array
3. refer to this thread: viewtopic.php?t=55383&highlight=usort
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

glob() is insanely slow.

Try using a directory handlers, a loop, and array sorting functions.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Why, pray tell, is this in Client Side?
Post Reply