Guest User

Brae

a guest
Dec 14th, 2009
1,599
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.02 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4.  
  5. function getDirTree($dir,$p=true) {
  6.     $d = dir($dir);$x=array();
  7.     while (false !== ($r = $d->read())) {
  8.         if($r!="."&&$r!=".."&&(($p==false&&is_dir($dir.$r))||$p==true)) {
  9.                 $x[$r] = (is_dir($dir.$r)?array():(is_file($dir.$r)?true:false));
  10.         }
  11.     }
  12.  
  13.     foreach ($x as $key => $value) {
  14.         if (is_dir($dir.$key."/")) {
  15.                 $x[$key] = getDirTree($dir.$key."/",$p);
  16.         }
  17.     }
  18.  
  19.     ksort($x);
  20.     return $x;
  21. }
  22. $path = "./res/gallery/painting/";
  23. $tree = getDirTree($path);
  24.  
  25. echo '<div id=gallery>';
  26.  
  27. foreach($tree as $element => $eval) {
  28.     if (is_array($eval)) {
  29.         foreach($eval as $file => $value) {
  30.                 if (strstr($file, "png")||strstr($file, "jpg")||strstr($file, "bmp")||strstr($file, "gif")) {
  31.                         $item = $path.$file;
  32.             $itemthumb = $path.'/thumbs/'.$file;
  33.                         echo '<a href="'.$item.'"><img src="'.$item.'" alt="'.$item.'"/></a>';
  34.                 }
  35.         }
  36.     }
  37. }
  38.  
  39. echo '</div>';
Advertisement
Add Comment
Please, Sign In to add comment