echo "<a href=?dir=".urlencode(trim(str_replace(" ", "[spc]",(str_replace("&", "[amp]",$CurrentDir))),'.\\')) . "&img=" . str_replace(" ", "[spc]",(str_replace("&", "[amp]",$i)))."><br> <img height=\"100\" border=\"0\" src=\"".$CurrentDir."/".$DirContents[$i]."\"><br></a>"; Вроде того? <? function getDirList ($dirName) { static $result_array=array(); $d = dir($dirName); while($entry = $d->read()) { if ($entry != "." && $entry != "..") { if (is_dir($dirName."/".$entry)) { array_push($result_array,$entry); //echo $dirName."/".$entry."<br>\n"; } } } $d->close(); sort($result_array); return $result_array; } function getDirContents ($dirName) { global $extensions; static $result_array=array(); $d = dir($dirName); //'.('png|jpg|gif|mng|jpeg)$ $regex = '.(' . implode('|', $extensions) . ')$'; while($entry = $d->read()) { if ($entry != "." && $entry != ".." && eregi($regex,$entry)) { if (!is_dir($dirName."/".$entry)) { str_replace(" ", "[spc]",(str_replace("&", "[amp]",$entry))); array_push($result_array,$entry); } } } $d->close(); sort($result_array); return $result_array; } // Load the directory tree $DirArray = getDirList(".\\franks"); for($i=0; $i < count($DirArray); $i++) { if($dir==$DirArray[$i]) { $DirIndex = $i; } } $NextDir = "showimages.php?dir=".$DirArray[$DirIndex + 1]; $PrevDir = "showimages.php?dir=".$DirArray[$DirIndex - 1]; $NextDirNam = $DirArray[($DirIndex + 1)]; $PrevDirNam = $DirArray[($DirIndex - 1)]; if ($DirIndex == 0) { $PrevDir = "showimages.php?dir=".$DirArray[(Count($DirArray) - 1)]; $PrevDirNam = $DirArray[(Count($DirArray) - 1)]; } if (($DirIndex + 1) > (Count($DirArray) - 1)) { $NextDir = "showimages.php?dir=".$DirArray[0]; $NextDirNam = $DirArray[0]; } ?> <? // File types global $extensions; $extensions = array('jpg', 'gif', 'png', 'svg'); echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr>"; $Column = 1; $DirName = $DirArray[$DirIndex]; $CurrentDir = ".\\franks\\" . $DirName; echo $CurrentDir; $DirContents = getDirContents($CurrentDir); for($i=0; $i < count($DirContents); $i++) { echo "<a href=?dir=".urlencode(trim(str_replace(" ", "[spc]",(str_replace("&", "[amp]",$CurrentDir))),'.\\')) . "&img=" . str_replace(" ", "[spc]",(str_replace("&", "[amp]",$i)))."><br> <img height=\"100\" border=\"0\" src=\"".$CurrentDir."/".$DirContents[$i]."\"><br></a>"; if($Column==5) { $Column = 0; echo "</tr>"; } $Column++; } if($Column != 0) { for($i=$Column; $i<8;$i++){ echo "<td>"; } } echo "</table>"; ?> Вот вариант с типами файлов.