Display images in a directory with php


Here’s a quick and dirty way to show all the files in a directory. I use this in my images folder to see what’s there. Some improvements would be to add a mime-type check or a *jpg check.

<?php

$path = "./";
$dir_handle = @opendir($path) or die("Unable to open folder");

while (false !== ($file = readdir($dir_handle))) {

if($file == "list2.php")
continue;
if($file == "list.php")
continue;
if($file == ".")
continue;
if($file == "..")
continue;

echo "<img src='$file' alt='$file' height=475 width=600><br />";

}
closedir($dir_handle);

?>