Jump to content

Default sorting order of a server


gordon.c

Recommended Posts

Hello,

 

I am having major issues with default sorting of the server. At my local virtual server (WAMP) the sorting order of files and folders is as expected. I never had to change any settings.

 

However when I use the exact same script on an online server the default sorting order is completely out of any logical explanation.

Please see for yourself.

 

scaled.php?server=823&filename=3252012104249am.png&res=medium

 

Can I change the default sorting in .htaccess or some other way? I would like to avoid using arrays in this case...

Link to comment
Share on other sites

Nope, the menu items are folders pulled by opendir();

 

I would like to avoid using arrays in this case if possible.

 

I am looking for some general server setting because its very strange that two different servers each use very different sorting system.

Link to comment
Share on other sites

It sounds like you're wanting to tackle this as a server issue rather than handling the issue with PHP so not sure I can help you here. You may want to post something specific to your servers OS.

 

Worth pointing out that if you do handle this with a server config solution, you may find your script doesn't work as expected should you port the code to a different server set up. If you use arrays, you shouldn't have this problem.

Link to comment
Share on other sites

Not sure about that but if there is something you can plug into .htaccess - I don't think that would work either since it's the OS itself that will determine the order of the files. If there is a directive to order the files, I would imagine that is something to be used in conjunction with listing the files in the directory (i.e Options Indexes) not actually changing the way the server stores it.

Link to comment
Share on other sites

(if something of that sort even exists)

 

No, there is no setting anywhere you can change to affect the order of the results from reading a directory.  Your only option to sort them is to store the results into an array first and sort the array.

 

The results of reading a directory are returned in what is known as "filesystem order" which depends on how the particular file system in use manages the files.  Short of creating your own filesystem there's no way to change what order it returns things in.

 

Link to comment
Share on other sites

(if something of that sort even exists)

 

No, there is no setting anywhere you can change to affect the order of the results from reading a directory.  Your only option to sort them is to store the results into an array first and sort the array.

 

The results of reading a directory are returned in what is known as "filesystem order" which depends on how the particular file system in use manages the files.  Short of creating your own filesystem there's no way to change what order it returns things in.

 

 

Oh I see... Well then its clear now.

 

Just out of curiosity. What ordering pattern is use in example you see at the top? I mean on my local virtual server it is clearly alphabetical order but on the online server (image above) I cant even remotely figure out what kind of ordering is that :-)

Link to comment
Share on other sites

There is not a pattern.

 

The order that you get the file names is the order that the file names are stored in the disk directory. The order is generally in the order that the files were created, but things like disk optimizers can re-order the disk directory. Also, doing things like displaying a folder of files in a particular order and then copying (FTP'ing) them to another folder, will place the files in that order in the new folder.

 

Adding a file to an existing folder can place it at any point in the directory, because empty directory entries get reused.

 

You must specifically order the file names after you read them if you want them in any particular order.

 

Whatever your reluctance is to read the file names into an array and sort them, get over it. Note: by default glob returns files alphabetically sorted.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.