Forum Moderators: coopster

Message Too Old, No Replies

files sorting in directory

         

oliver_new

8:41 am on Apr 18, 2005 (gmt 0)

10+ Year Member



Hi there, I am completely new to this forum, havent found anything on the subject, so I try it here. Any help is appreciated, even if it is just redirection to another thread or forum.

Can anybody tell me how files are sorted in remote directories on an Apache server?

I am working with files and directories in php, having pictures in a directory and let php find and display them automatically. However, the sorting of the pictures is all mixed up, they only seem to be sorted by filename, but are in some cases not. I have experimented with uploading them once again, all in a bunch as well as picture by picture. it gives me various results, I can not recognize any pattern in the sorting.

I am very grateful for any help.

Thanks,
Oliver

dreamcatcher

9:52 am on Apr 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi oliver_new, welcome to Webmaster World. :)

Have you tried reading the contents of the directory, assigning them to an array, then sorting the array?

dc

oliver_new

10:49 am on Apr 18, 2005 (gmt 0)

10+ Year Member



that sounds like a perfect solution, thanks I'll try it.

Still, as I'm curious, I wonder how the server sorts the files.

Thanks for the hint,
Oliver

jd01

11:17 am on Apr 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I believe default is by file name, where it gets interesting is CAPS come first... so the real sort is A-Z then a-z.

If you have access to the configuration, via shell, etc. you can usually select a default sort that is more to your liking. EG type or size.

Justin

henry0

11:36 am on Apr 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oliver,
WebmasterWorld has an Apache forum :)

Regards

Henry

oliver_new

11:50 am on Apr 18, 2005 (gmt 0)

10+ Year Member



thanks td, i dont think I can get into configuration, its just a basic webhost service. fact is, the files are not sorted by filename, at least not when PHP reads through them one by one, i use only lower-case-filenames.

Henry, thanks for the hint, I'll try it there too.

dmmh

4:14 pm on Apr 18, 2005 (gmt 0)

10+ Year Member



u restting the array before reading it? ;)

coopster

10:42 am on Apr 19, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The filenames are returned in the order in which they are stored by the filesystem. You are better off handling your sort order once the files have been read into an array.

oliver_new

11:03 am on Apr 19, 2005 (gmt 0)

10+ Year Member



thanks to all of you,

i believe I have good insight into the situation now. it will probably take a couple of days untill i get to work on the code again, but I'll let you know about the results..

Oliver