Opening and reading director produces random order
| From: | Jeffry Killen | Date: | Tue, 09 Dec 2014 20:05:42 +0000 |
| Subject: | Opening and reading director produces random order | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-324101@lists.php.net to get a copy of this message | ||
Hello;
I have the following section of code that opens and reads a dir and assembles the contents
into html table markup:
The question is: when this is run on my remote hosting service, the list comes out in a random order, Why and what can I do
programatically to correct the order?
The remote system is running on a Linux platform, but that shouldn't make a difference. I seem to remember somewhere in the
php manual that the sort order may be random and that there was a function for producing a natural sort(?)
(while at home in local dev server: Apache running on Mac OSX, the list comes out in the order it
appears in the directory)
Thank you for time and attention
JK
the code:
@$_dr = opendir($_dir);
if(!$_dr)
{
$_stat = '';
if(!is_dir($_dir))
{
$_stat = 'not found';
}
else if(!is_readable($_dir))
{
$_stat = 'not readable';
}
$_out['error'] = "_CONSOLE->mkList() error: ".$_dir." not opened for read: ".$_stat;
return $_out['error'];
}
$_itr = 0;
$_out['mrkUp'] = "<table><tr><td><span class=\"norm\">Owner</span></td><td><span class=\"norm\">type and permissions</span></td><td><span class=\"norm\">Octal value</span></td><td><span class=\"norm\">Name</span></td></tr>\n";
while(false !== ($_x = readdir($_dr)))
{
$_owner = self::getOwner($_dir.$_x);
$_octPerms = substr(sprintf('%o', fileperms($_dir.$_x)), -4);
$_out['mrkUp'] .= "<tr><td><span class=\"norm\" id=\"o_".$_itr."\">".$_owner."</span></td><td><span class=\"norm\" id=\"p_".$_itr."\">".self::getWRXPerms($_dir.$_x)."</span></td><td><span class=\"norm\" id=\"r_".$_itr."\">".$_octPerms."</span></td><td><span class=\"norm\" id=\"n_".$_itr."\">".basename($_x)."</span></td></tr>\n";
$_itr++;
}
closedir($_dr);
$_out['mrkUp'] .= "</table>";
return $_out;