gordon.c Posted March 25, 2012 Share Posted March 25, 2012 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. Can I change the default sorting in .htaccess or some other way? I would like to avoid using arrays in this case... Quote Link to comment https://forums.phpfreaks.com/topic/259670-default-sorting-order-of-a-server/ Share on other sites More sharing options...
l0gic Posted March 25, 2012 Share Posted March 25, 2012 Are your menu items pulled from a database? If so using SORT in your queries may help. Quote Link to comment https://forums.phpfreaks.com/topic/259670-default-sorting-order-of-a-server/#findComment-1330883 Share on other sites More sharing options...
gordon.c Posted March 25, 2012 Author Share Posted March 25, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/259670-default-sorting-order-of-a-server/#findComment-1330891 Share on other sites More sharing options...
titan21 Posted March 25, 2012 Share Posted March 25, 2012 I assume you're using readdir() to pull the info. The manual states that readdir() pulls the info in the order dictated by the server. Your best bet would be to pull the data into an array and sort it based on some condition. Quote Link to comment https://forums.phpfreaks.com/topic/259670-default-sorting-order-of-a-server/#findComment-1330898 Share on other sites More sharing options...
gordon.c Posted March 25, 2012 Author Share Posted March 25, 2012 I am using opendir() function and I would like to avoid using arrays in this case if possible. The sorting order has to be specified somewhere right. As I said my local virtual machine pulls the files in correct order. Quote Link to comment https://forums.phpfreaks.com/topic/259670-default-sorting-order-of-a-server/#findComment-1330900 Share on other sites More sharing options...
titan21 Posted March 25, 2012 Share Posted March 25, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/259670-default-sorting-order-of-a-server/#findComment-1330907 Share on other sites More sharing options...
gordon.c Posted March 25, 2012 Author Share Posted March 25, 2012 Its true that this concerns more the server than php. I guess I am looking for something like a line that goes into .htaccess which would change the file system of the server (if something of that sort even exists) Quote Link to comment https://forums.phpfreaks.com/topic/259670-default-sorting-order-of-a-server/#findComment-1330915 Share on other sites More sharing options...
titan21 Posted March 25, 2012 Share Posted March 25, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/259670-default-sorting-order-of-a-server/#findComment-1330923 Share on other sites More sharing options...
gordon.c Posted March 25, 2012 Author Share Posted March 25, 2012 If I find something useful I will share it... So far it seems I will have to stick to arrays then Quote Link to comment https://forums.phpfreaks.com/topic/259670-default-sorting-order-of-a-server/#findComment-1330924 Share on other sites More sharing options...
kicken Posted March 25, 2012 Share Posted March 25, 2012 (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. Quote Link to comment https://forums.phpfreaks.com/topic/259670-default-sorting-order-of-a-server/#findComment-1330925 Share on other sites More sharing options...
gordon.c Posted March 25, 2012 Author Share Posted March 25, 2012 (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 :-) Quote Link to comment https://forums.phpfreaks.com/topic/259670-default-sorting-order-of-a-server/#findComment-1330938 Share on other sites More sharing options...
PFMaBiSmAd Posted March 25, 2012 Share Posted March 25, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/259670-default-sorting-order-of-a-server/#findComment-1330948 Share on other sites More sharing options...
gordon.c Posted March 25, 2012 Author Share Posted March 25, 2012 So I sorted it out by using arrays afterall. It was a little bit more code but it works now. Thank you all for help Quote Link to comment https://forums.phpfreaks.com/topic/259670-default-sorting-order-of-a-server/#findComment-1330957 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.