Reputation: 3
I use this code to list all files in directory:
$d = dir($FolderToPlay);
while (($file = $d->read()) !== false){
...
...
}
$d->close();
But, the result is not in the numerical order. How can I fix it?
Upvotes: 0
Views: 57
Reputation: 780889
Get a list of all the filenames, then you can use a sorting function.
$d = glob("$FolderToPlay/*");
natsort($d);
foreach ($d as $file) {
...
}
Upvotes: 1
Reputation: 2277
The easiest way to list all files in a directory is with scarndir() fuction. You can use it like this:
//Create a variable that contains all your files
$root = scandir($dir);
//Do something with each value, like push them into an array, do regex etc.
foreach($root as $value){
//...
}
Upvotes: 0