title: Listing and previewing images in a directory using PHP
body: <p>I'm trying to improve the administrator panel of my website. I need to preview the images in the thumbnails folder so that when i'm using thumbnails for news I dont have to upload the image for the second time. I found a great script, but I get failed to read the directory error. Here is the script:</p>
  
  <pre><code>&lt;?php
    // filetypes to display
    $imagetypes = array("image/jpeg", "image/gif", "image/png");
  
    // Original PHP code by Chirp Internet: www.chirp.com.au
    // Please acknowledge use of this code by including this header.
  
    function getImages($dir)
    {
      global $imagetypes;
  
      // array to hold return value
      $retval = array();
  
      // add trailing slash if missing
      if(substr($dir, -1) != "/") $dir .= "/";
  
      // full server path to directory
      $fulldir = "{$_SERVER['DOCUMENT_ROOT']}/$dir";
  
      $d = @dir($fulldir) or die("getImages: Failed opening directory $dir for reading");
      while(false !== ($entry = $d-&gt;read())) {
        // skip hidden files
        if($entry[0] == ".") continue;
  
        // check for image files
        $f = escapeshellarg("$fulldir$entry");
        $mimetype = trim(`file -bi $f`);
        foreach($imagetypes as $valid_type) {
          if(preg_match("@^{$valid_type}@", $mimetype)) {
            $retval[] = array(
             'file' =&gt; "/$dir$entry",
             'size' =&gt; getimagesize("$fulldir$entry")
            );
            break;
          }
        }
      }
      $d-&gt;close();
  
      return $retval;
    }
  
    // fetch image details
    $images = getImages("../images/thumbnails");
  
    // display on page
    foreach($images as $img) {
      echo "&lt;div class=\"photo\"&gt;";
      echo "&lt;img src=\"{$img['file']}\" {$img['size'][3]} alt=\"\"&gt;&lt;br&gt;\n";
      // display image file name as link
      echo "&lt;a href=\"{$img['file']}\"&gt;",basename($img['file']),"&lt;/a&gt;&lt;br&gt;\n";
      // display image dimenstions
      echo "({$img['size'][0]} x {$img['size'][1]} pixels)&lt;br&gt;\n";
      // display mime_type
      echo $img['size']['mime'];
      echo "&lt;/div&gt;\n";
    }
  ?&gt;
  </code></pre>
  
  <p>I really appreciate if someone could help..</p>
  
  <p><strong>EDIT:</strong></p>
  
  <pre><code>&lt;div style=" height: 200px; width: 600px; overflow: auto;"&gt;
  &lt;?PHP
   foreach(glob("../thumbnail/".'*') as $filename){
      echo "&lt;div style=\"display:inline-table; font-size:10px; font-family:'Tahoma'; margin:5px;\"&gt;";
      echo "&lt;img width=\"100px\" height=\"100px\" src=\"../thumbnail/$filename\"/&gt;";
      echo "&lt;br&gt;".basename($filename) . "&lt;br&gt;";
      echo "&lt;/div&gt;";
  }
  ?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This method works perfect. No need to use complicated scripts.
  Anyway, can somebody please tell me how to check images less than 100px x 100px displayed?</p>