Display images in a directory with php

Posted: February 28th, 2009 | Author: jriggs | Filed under: php | Tags: , , | No Comments »

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);

?>

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Reddit
  • RSS
  • StumbleUpon

Related posts:

  1. Address Standardization & Verification with USPS web tools and PHP
  2. php: Create Url Safe Encrypted String

Comments are closed.