All pastes #632955 Raw Edit

Something

public text v1 · immutable
#632955 ·published 2007-07-25 10:11 UTC
rendered paste body
<?php

// $path : path to browse
// $maxdepth : how deep to browse (-1=unlimited)
// $mode : "FULL"|"DIRS"|"FILES"
// $d : must not be defined
  
function searchdir ( $path , $maxdepth = -1 , $mode = "FULL" , $d = 0 )
{
   if ( substr ( $path , strlen ( $path ) - 1 ) != '/' ) { $path .= '/' ; }      
   $dirlist = array () ;
   if ( $mode != "FILES" ) { $dirlist[] = $path ; }
   if ( $handle = opendir ( $path ) )
   {
       while ( false !== ( $file = readdir ( $handle ) ) )
       {
           if ( $file != '.' && $file != '..' )
           { 
            $varr = explode(".", $file);
            if ((end($varr) == 'jpg') || (end($varr) == 'pps') || (end($varr) == 'png') || (end($varr) == 'gif'))
            {
             $file = $path . $file ;
               if ( ! is_dir ( $file ) ) { if ( $mode != "DIRS" ) { $dirlist[] = $file ; } }
               elseif ( $d >=0 && ($d < $maxdepth || $maxdepth < 0) )
               {
                   $result = searchdir ( $file . '/' , $maxdepth , $mode , $d + 1 ) ;
                   $dirlist = array_merge ( $dirlist , $result ) ;
               }
            }
       }
       }
       closedir ( $handle ) ;
   }
   if ( $d == 0 ) { natcasesort ( $dirlist ) ; }
   return ( $dirlist ) ;
}

$dirarr = searchdir('./', 0, 'FILES');

$randnum = rand(1,count($dirarr));

$level = 0;
$array = $dirarr;

foreach ($array as $v) {
 $level = $level + 1;
 $curstr = substr($v, 2, strlen($v));
 print '<a href="' . $curstr . '">' . $level . ') ' . $curstr . '</a><br/>' . chr(13);
 if ($level == $randnum) $rcurcstr = $curstr;
}
print '/End of Content';