RE: [PHP-WIN] Windows paths and opendir()
| From: | Bill Bolte | Date: | Mon, 08 Jan 2007 15:07:21 +0000 |
| Subject: | RE: [PHP-WIN] Windows paths and opendir() | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-27357@lists.php.net to get a copy of this message | ||
Your code worked fine for me - however, I did get this message at the
end:
"Notice: Undefined offset: 117 in C:\WebSites\Text Editor
Example\dir.php on line 11"
Other than that, it functioned as it looks like it should...
-----Original Message-----
From: Beauford [mailto:phpuser@netscan.ca]
Sent: Saturday, January 06, 2007 3:05 PM
To: php-windows@lists.php.net
Subject: [PHP-WIN] Windows paths and opendir()
Hi,
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]."<br>"; }
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