Windows paths and opendir()
am 06.01.2007 22:05:02 von BeaufordHi,
I have been banging my head for the last 4 hours trying to get this to work.
I simply want to be able to display a directory listing of a drive and
directory. i.e. d:\directoryname. Is this even possible???? Any help is
appreciated. I am using IIS 6 and PHP 4.4.
This is the error I get:
Warning: opendir(f:\downloads\): failed to open dir: Invalid argument in
c:\web\index.php on line 30
***** This is line 30 - if ( $handle = opendir ( $page ) )
This is the code:
$page = "f:\\downloads";
// $mode : "FULL"|"DIRS"|"FILES"
// $d : must not be defined
$display = searchdir($page);
$num = count($display);
$i = 0;
for($i = 0; $i <= $num; $i++) { echo $i." ".$display[$i]."
"; }
function searchdir ( $page , $maxdepth = -1 , $mode = "FILES" , $d = 0 )
{
if ( substr ( $page , strlen ( $page ) - 1 ) != '\\' ) { $page .= '\\' ;
}
$dirlist = array () ;
if ( $mode != "FILES" ) { $dirlist[] = $page ; }
if ( $handle = opendir ( $page ) )
{
while ( false !== ( $file = readdir ( $handle ) ) )
{
if ( $file != '.' && $file != '..' )
{
$file = $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 ) ;
}
?>
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php