Forum Moderators: coopster
$dir = $_SERVER['DOCUMENT_ROOT'] . "/myfolder";
$ext = 'png|jpe*g|gif'; // match jpg or jpeg
if ($handle = opendir($dir)) {
echo "<ul>";
while (false !== ($file = readdir($handle))) {
if (is_dir("$dir/$file")) {
echo "<li>Directory: $dir/$file</li>";
}
else if (is_file("$dir/$file") and preg_match('/^.*\.$ext$/i',$file)) {
echo "<li>File: $dir/$file</li>";
}
}
closedir($handle);
echo "</ul>";
}
else { echo "<p>$dir has no files that match.</p>"; }