maxyudin

Get list of images in given directory

Oct 4th, 2011
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.41 KB | None | 0 0
  1. /*
  2. Get list of images in given directory
  3. */
  4.  
  5. function get_image_list($dir)  {
  6.     $files = array();
  7.     $h = opendir($dir);
  8.     while ( false !== ( $file = readdir($h) ) ) {
  9.          // if file isn't this directory or its parent
  10.         if ($file != '.'
  11.             && $file != '..'
  12.             && !is_dir($dir.'/'.$file)
  13.             && preg_match('@(gif|png|jpg|jpeg)$@i', $file) ) {
  14.                 $files[] = $file;
  15.         }
  16.     }
  17.     closedir($h);
  18.  
  19.     return $files;
  20. }
  21.  
Advertisement
Add Comment
Please, Sign In to add comment