1. <?php
  2.  
  3. function thumbList($folder, $thumb, $img)
  4. {
  5. $banned = array(".", "..", "index.php", "error_log");
  6.  
  7. //leave blank
  8. $html = '<ul class="thumbNail">';
  9.  
  10. if ($handle = opendir($folder))
  11. {
  12. // List all the files
  13. while ( false !== ( $file = readdir($handle) ) )
  14. {
  15. $pos = strrpos($file, ".");
  16. $ok = false;
  17.  
  18. if( !in_array($file, $banned) && $pos )
  19. {
  20. //if file contains _thumb, do not link to it
  21. if(strstr($file, "_thumb"))
  22. {
  23. $ok=false;
  24. } else {
  25. $ok=true;
  26. }
  27.  
  28. $file = substr($file, 0, $pos);
  29. //if the item is the normal img, display corresponding thumb and link to large img
  30. if($ok)
  31. $html .= "<li><a href='$file$img' title='$file'><img src='$file$thumb' /></a></li>";
  32.  
  33. }
  34. }
  35.  
  36. closedir($handle);
  37. $html .= '</ul>';
  38. echo $html;
  39. }
  40. }
  41.  
  42.  
  43. //Set all your variables here and call the function for each folder
  44. $folder = ".";
  45. $thumb = "_thumb.jpg";
  46. $img = ".jpg";
  47.  
  48. thumbList($folder, $thumb, $img);
  49.  
  50. ?>
  51. </ul>
  52.