// create directory listing array $listing = array(); // open directory (NOTE: you can change opendir()'s argument to be any dir) $dh = opendir(".") or die("Couldn't open directory"); // read through dir contents while a file exists while (!(($file=readdir($dh))===false)) { // skip special cases (NOTE: replace "index.php" with the name of the file you put this snippet in) if ($file=="index.php" || $file==".htaccess" || is_dir($file) || filesize($file)==0 || !strpos($file,".")) continue; // produce human-readable file size $mb = null; $kb = filesize($file)/1024; if ($kb>=1000) $mb = sprintf("%.2f",$kb/1024); else $kb = sprintf("%.2f",$kb); $size = (isset($mb))? "$mb MB" : "$kb KB"; // add a link to the file to the listing array array_push($listing,"$file [$size]"); } // close directory closedir($dh); // clear the cache clearstatcache(); // sort the files natcasesort($listing); // echo the files in an unordered list echo "\n";