0

Although this code SORTS the filename and then SORTS the extension perfectly locally, I cannot get this to work on any Hosting company's (shared) server - regardless of the PHP version. It simply will not do any sorting on my Host's server. I have tried this on many different hosting companies' servers. So this is not an issue with one hosting company/server. (*FYI: The oldest version of PHP tested was 5.2.17 - most recent tested was 5.3.26. Local = 5.3.5)

OUTPUT EXAMPLE:
a_first.jpg
a_first.png
a_first.zip
b_second.doc
b_second.gif
b_second.jpg

<?php

function getFileExt($filename) {
    return substr(strrchr($filename,'.'),1);
}

$handle=opendir(dirname(__FILE__));

while (($file = readdir($handle))!==false) {
    $fileExt = strtolower(getFileExt($file));
    if(in_array($file, $ignore_file_list)) { continue; }
    if(in_array($fileExt, $ignore_ext_list)) { continue; }
    if(is_dir($file)) { $fileExt = "dir"; }

    /* SORT FILES - First by filename and then by extension */
    $files = glob($handle."/*.*");
    $files = array_map("basename", $files);

    natcasesort($files);

    echo '
<div><a href='.$file.' class='.$fileExt.'>&nbsp;</a></div>
<div><a href='.$file.'>$file</a></div>
';
}

closedir($handle);

?>

Please refer to this posting for more info:
PHP - Sort data after original sort

Community
  • 1
  • 1
mar2195
  • 103
  • 1
  • 10
  • 1
    why you passing a handle to `glob` ? – DevZer0 Jul 09 '13 at 06:06
  • Please refer to this posting: [http://stackoverflow.com/questions/17509221/php-sort-data-after-original-sort](http://stackoverflow.com/questions/17509221/php-sort-data-after-original-sort) - This will give you insight regarding this issue. I have also tried " dirname ( _ _ FILE _ _ ) " - no luck. – mar2195 Jul 09 '13 at 06:10
  • @mar2195: this might helps you http://stackoverflow.com/questions/884974/sort-and-display-directory-list-alphabetically-using-opendir-in-php – dakshbhatt21 Jul 09 '13 at 07:05

0 Answers0