<?
  function list_gif_and_jpg_files($the_directory) {
  #
  # path name to the file with the images
  #
  if ( $the_directory == '') {
     $the_directory='images_for_counters';
  }
  #
  # get an array to hold all the names of gif and jpg files
  #
  $dl = array();
  #
  # read the directory and get all the gif and jpg images
  #
  if ($hd = opendir($the_directory))
  {
    #
    # read each file name in the directory
    #
    while ($sz = readdir($hd)) {
       #
       # if the file is a jpg or gif file keep it
       # else skip the file
       # 
       if (preg_match("/[0-9]\.(gif|jpg)$/i",$sz)) { 
          $dl[] = $sz;
       }
    }
    #
    # close the directory. we are done reading it
    #
    closedir($hd);
    #
    # sort the file names
    #
    asort($dl);
    #
    # print out the images and image names
    # in a table
    #


    echo "<table border=1 style=\"background-image: url(images_for_counters/plaid.jpg)\">";
    foreach ($dl as $value) {
       $the_image=$the_directory."/".$value;
       #
       # a lot of the images are invisible images :)
       # well they are 1 pixel wide by 1 pixel tall
       # which is ALMOST invisible
       # if the lenght or width of the image is less then 10 pixels
       # display it as 10 pixels so we can see the image with out
       # going blind
       #
       list($width, $height, $type, $attr) = getimagesize($the_image);
       if ($width < 10) {
           $width=10;
       }
       if ($height < 10) {
           $height=10;
       }
       print "<tr valign=\"bottom\"><td><img src=\"$the_image\" width=$width height=$height></td><td>$value</td></tr>";
    }
    echo "</table>";
  }
 }
?>