sam85281
asked on
opendir() sorting problem.
First, a question. What does opendir() sort by as a default????
I have this in a directory:
01_blahblah.mp3
02_blahblah.mp3
03_blahblah.mp3
04_blahblah.mp3
05_blahblah.mp3
06_blahblah.mp3
In the directory it IS sorted correctly. When I run opendir() it sorts them as: 01, 03, 04, 05, 06, 02.
There is no sense to this. It's not sorted by date, fileSize, numerically, OR alphabetically.
Obviously I want them to sort numerically.
Here's the code I'm using to get my results:
if ($handle = opendir('audio')) {
$i = 1;
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "&file".$i."=".$file;
$i++;
}
}
closedir($handle);
}
$i--;
echo "&total=".$i;
The results feed into a Flash movie in the format of:
&file1=01_blahblah.mp3&fil e2=02_blah blah.mp3&f ile3=03_bl ahblah.mp3 &file4=04_ blahblah.m p3&file5=0 5_blahblah .mp3&file6 =06_blahbl ah.mp3&tot al=6
It currently all works other than the order being wrong.
How can I get this to order right?
Thanks,
-Sam
I have this in a directory:
01_blahblah.mp3
02_blahblah.mp3
03_blahblah.mp3
04_blahblah.mp3
05_blahblah.mp3
06_blahblah.mp3
In the directory it IS sorted correctly. When I run opendir() it sorts them as: 01, 03, 04, 05, 06, 02.
There is no sense to this. It's not sorted by date, fileSize, numerically, OR alphabetically.
Obviously I want them to sort numerically.
Here's the code I'm using to get my results:
if ($handle = opendir('audio')) {
$i = 1;
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "&file".$i."=".$file;
$i++;
}
}
closedir($handle);
}
$i--;
echo "&total=".$i;
The results feed into a Flash movie in the format of:
&file1=01_blahblah.mp3&fil
It currently all works other than the order being wrong.
How can I get this to order right?
Thanks,
-Sam
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
no problem :)
For custom sorting by other parameters (file size, creation date etc - whatever you need) You may take a look at
https://www.experts-exchange.com/questions/21213726/Directory-listing-sort-array-by-filename-and-then-extension-type.html
https://www.experts-exchange.com/questions/21213726/Directory-listing-sort-array-by-filename-and-then-extension-type.html
ZhaawZ, please don't encourage point hungry behaviour.
Hi sam85281,
If you have a free moment could you close this question.
Thanks,
Diablo84
If you have a free moment could you close this question.
Thanks,
Diablo84
ASKER
Wow. I thought I did close it! Closing now....
ASKER