<?php $dir = htmlspecialchars($_GET["dir"]); $className = htmlspecialchars($_GET["className"]); if ($handle = opendir($dir)) { echo "<div class='photogallery $className'><ul>"; while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != ".." && preg_match('/(jpg)|(JPG)$/', $entry) == 1) { $path = $dir."/".$entry; $pathThumb = $dir."/thumbs/".$entry; echo " <li> <a href='/$path' data-lightbox='gallery1' data-title=''><img src='/$pathThumb' alt=''></a> </li>"; } } closedir($handle); echo "</ul><div class='both'></div></div>"; } ?>
$temp=""; while ( ..... ){ // use concatenation for html in a temporary var if (is_file($entry)){ $temp .= "<li> ......</li> } } echo "<ul>".$temp."</ul><div>........" :
PHP: readdir - Manual[^] The entries are returned in the order in which they are stored by the filesystem.
PHP: scandir - Manual[^] sorting_order By default, the sorted order is alphabetical in ascending order. If the optional sorting_order is set to SCANDIR_SORT_DESCENDING, then the sort order is alphabetical in descending order. If it is set to SCANDIR_SORT_NONE then the result is unsorted.
sorting_order
SCANDIR_SORT_DESCENDING
SCANDIR_SORT_NONE
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)