I'm using MaxiDVD's contribution for images on my oscommerce enabled site, the problem is that the image directory popup doesn't display the files/folders sorted. I want to add either the natcasesort function or the sort function, to the code to do this but not exactly sure where it needs to go in the lister.php file (see attached)
I want to sort the directories and the files in the directories. I found this contrib on php. net under the readdir() function for sorting using the natcasesort function but not exactly sure where in lister.php, it should go, or if it needs to be called more than once.
I've tried several places and I haven't gotten it to work yet. Here's the contrib from php.net...
<?php
$path = $_SERVER[DOCUMENT_ROOT]."/old/";
$dh = @opendir($path);
while (false !== ($file=@readdir($dh)))
{
if (substr($file,0,1)!=".") #skip anything that starts with a '.'
{ #i.e.:('.', '..', or any hidden file)
if (is_dir($path.$file))
$dirs[]=$file.'/'; #put directories into dirs[] and append a '/' to differentiate
else
$files[]=$file; #everything else goes into files[]
}
}
@closedir($dh);
if ($files)
natcasesort($files); #natural case insensitive sort
if ($dirs)
natcasesort($dirs);
$files=array_merge($dirs,$files); #merge dirs[] and files[] into files with dirs first
foreach ($files as $file) #that's all folks, display sorted all folders and files
echo "$file<br>\n";
?>
And maxiDVD's lister.php contribution is attached with .txt extension due to restrictions on php builder.
I'm still new at this and learning slowly, (I'm in my 50's trying to learn a new language, so be gentle please) Thanks.