note 58120 deleted from ref.dir by sniper
| From: | sniper@php.net | Date: | Thu, 15 Dec 2005 23:59:18 +0000 |
| Subject: | note 58120 deleted from ref.dir by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-100243@lists.php.net to get a copy of this message | ||
Note Submitter: josh _at_ thenewfood _dot_ com
----
Small correction to Nicolas Merlet's searchdir() function. To allow unlimited depth ($maxdepth
= -1), the line
<?php elseif ( $d >=0 && $d < $maxdepth ) ?>
must be changed to
<?php elseif ( $d >=0 && ($d < $maxdepth || $maxdepth < 0) ) ?>
Corrected version:
<?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 != '..' )
{
$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 ) ;
}
?>