$path="$var"; $dh=opendir($path); while (false !== ($mfile[]=readdir($dh))) { } natsort($mfile); foreach ($mfile as $key => $pics) { if (substr($pics,-4,4) == ".gif" or substr($pics,-4,4) == ".jpg" or substr($pics,-4,4) == ".JPG") { echo "
"; } } ?>