> -----Original Message----- > From: Jochem Maas [mailto:jochem@xxxxxxxxxxxxx] > Sent: January 7, 2007 8:35 PM > To: Beauford > Cc: 'PHP' > Subject: Re: Windows directory listings > > with regard to trolling - I'd don't *just* do that :-) > > sometime I even get the answer to the question correct :-) > let's see if I can help ... > > Beauford wrote: > > Maybe I should clarify. When I use a windows path > (c:\whatever) I get > > an error that it can't find the path. In Linux the same code works > > fine (/usr/local/whatever). > > > > Here is all the relevent info. > > > > 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"; > > you got this part right (escaping the backslash) > > > // $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 .= > > '\\' ;} > > this if statement will run given the value of $page, it's not > needed AFAIKT. > then again I can't see it causing problems. This makes no difference. I took it out before and got the same error. > btw: php defines a constant DIRECTORY_SEPARATOR automatically > which may help you make your code more portable, and save you > having to think/worry about the blacksdlashing 'problem'. > > > $dirlist = array () ; > > if ( $mode != "FILES" ) { $dirlist[] = $page ; } > > right here I suggest adding a check using is_dir() and > is_readable() on the $page var. > for now stick in a bit of debug code ... > > echo '<pre>'; > var_dump($path, is_dir($path), is_readable($path)); echo '</pre>'; I checked the NTFS permissions and they are fine, and the local directory displays fine. By this I mean the directory where this script is. So if the script is in c:\test I can read c:\test, c:\test\test2. c:\test\test3, ../test2. etc. It only happens when I go outside of the current drive. So if I put $page = "test", or $page = "test3", or $page = "../" they will all work. As soon as I add a drive letter, it gives me the error. Even on the local machine. I am trying to access a networked drive, but I have a share on the PC where the script is . May this is the issue. Is there a way to use a UNC path? > I'm guessing that is_readable() is going to return false, > which would point the fact that either the drive or the > directory is not readable by the webserver process (you don't > mention whether you are running via a the webserver but I > assume you are given the output your generating include a > '<br>') - the situation maybe compounded by the fact that F: > is actually a mapped drive of some sorts (I have no idea what > kind of trouble this could cause). > > > > > 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 ) ; > > } > > > > ?> > > > >> -----Original Message----- > >> From: Jochem Maas [mailto:jochem@xxxxxxxxxxxxx] > >> Sent: January 7, 2007 10:25 AM > >> To: Beauford > >> Cc: PHP > >> Subject: Re: Windows directory listings > >> > >> Beauford wrote: > >>> Hi, > >>> > >>> I am trying to write a script that reads a directory on > >> Windows. All > >>> the PHP functions I have looked at all seem to work with > the Linux > >>> dietary > >> it sounds more like you have found an examples that show windows > >> being used (i.e. windows file paths). > >> > >>> structure. Is there another way to do this. > >> you must be reading a manual that only exists in your particular > >> parallel universe, all relevant php function work in > windows as well > >> as linux: > >> > >> http://php.net/manual/en/ref.filesystem.php > >> http://php.net/dir > >> > >>> Thanks > >>> > >> > >> > > > > -- > PHP General Mailing List (http://www.php.net/) To > unsubscribe, visit: http://www.php.net/unsub.php > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php