PHP Script to list and display all images in a directory

<?php
 
$path = "./";
$dir_handle = @opendir($path) or die("Unable to open folder");
 
while (false !== ($file = readdir($dir_handle))) {
 
	if (strpos($file,'.jpg') ||strpos($file,'.gif')||strpos($file,'.png')) {
		echo "<img src='$file' alt='$file'><br />";
	}
}
closedir($dir_handle);
 
?>

Demo

One thought on “PHP Script to list and display all images in a directory”

  1. I just wanted to post a quick note about a great php image rotator script that I just found on A List Apart . It was one of the most painless scripts I have ever setup. I needed a little script that would rotate images everytime you visited this client’s homepage, I figured I could create a script if needed – but I always Google it first.

Leave a Reply

Your email address will not be published.