1024 && $a['size'] <= 1024*1024) $files[$fkey]['sizetext'] = (ceil($a['size']/1024*100)/100) . " K"; else if ($a['size'] > 1024*1024) $files[$fkey]['sizetext'] = (ceil($a['size']/(1024*1024)*100)/100) . " Mb"; else $files[$fkey]['sizetext'] = $a['size'] . " bytes"; $files[$fkey]['name'] = $file; $e = strip_ext($file); // $e is the extension - for example, .gif $files[$fkey]['type'] = filetype($fullpath); // file, dir, etc $k=$e.$file; // we use this string for sorting the array elements by extension and filename; $fileNames[$i++] = $k; } closedir($dh); } else die ("Cannot open directory: $path"); } else die ("Path is not a directory: $path"); sort($fileNames,SORT_STRING); // sorting $sortedFiles = array(); $i = 0; foreach($fileNames as $f) { $f = substr($f, 4, strlen($f)-4); // we remove the extension we added in front of the filename for sorting if($files[$f]['name'] !='') $sortedFiles[$i++] = $files[$f]; }// ends the foreach where we build the final sorted array return $sortedFiles; } // folder navigation code $startdir = "./"; if(isset($_GET['dir'])) { $prev = $_GET['dir']; $folder = $_GET['dir']; echo "

"; } else { $folder = $startdir; $prev='';} // end folder navigation code $files = getFiles($folder); foreach ($files as $file) { if(strip_ext($file[name])!='.php'){ $image = $img_file; if($file[type]=='dir') { $image = $img_folder; $cmd='?dir='.$prev.$file[name].'/'; }// if the element is a directory else $cmd=$prev.$file[name]; echo " $file[name]
"; }//if strip_ext }//foreach ?>