Advertisement
imoda

show all images in directory

Apr 5th, 2012
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.13 KB | None | 0 0
  1. <?php
  2.  
  3.     scanDirectoryImages('.');
  4.  
  5.     function scanDirectoryImages($directory) {
  6.        
  7.         if (substr($directory, -1) == '/') {
  8.            
  9.             $directory = substr($directory, 0, -1);
  10.         }
  11.         if (!file_exists($directory) || !is_dir($directory)) {
  12.            
  13.             return FALSE;
  14.         }
  15.         else if (is_readable($directory)) {
  16.            
  17.             $directory_tree = array();
  18.             $directory_list = opendir($directory);
  19.            
  20.             while($file = readdir($directory_list)) {
  21.                
  22.                 if ($file != '.' && $file != '..') {
  23.                    
  24.                     $path = $directory . '/' . $file;
  25.                    
  26.                     if (is_readable($path)) {
  27.                        
  28.                         $subdirectories = explode('/', $path);
  29.                        
  30.                         if (is_dir($path)) {
  31.                            
  32.                             scanDirectoryImages($path);
  33.                         }
  34.                         else if (is_file($path)) {
  35.                            
  36.                             $extension = end(explode('.', end($subdirectories)));
  37.                            
  38.                             if (in_array($extension, array('jpeg', 'jpg', 'gif', 'png'))) {
  39.                                
  40.                                 echo '<a href="' . $path . '"><img src="' . $path . '" style="max-height: 100px; max-width: 100px;" /></a>';
  41.                             }
  42.                         }
  43.                     }
  44.                 }
  45.             }
  46.            
  47.             closedir($directory_list);
  48.         }
  49.         else {
  50.            
  51.             return FALSE;
  52.         }
  53.     }
  54.  
  55. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement