Re: [PHP] Windows directory listings
Beauford wrote: > ... >>> >>> >>> 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. > I didn't think it would. ... > 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. the mapped drive should not be a problem. I definitely think it's a permission issue, of course I could be wrong. the following bug report *might* give you a clue as to whats going on: http://bugs.php.net/bug.php?id=22153&edit=1 I have a feeling the bit about setting the permissions of the Share to Everyone (on the server) is a good place to start. (the point about having to login to the share manually before php is able to connect is also noteworthy) also bare in mind that a Drive/Directory has a set of permissions that are seperate to the permissions of a Share that is defined for said Drive/Directory, (something that has always confused me a bit) - both need to be setup to appropriately > Is there a way to use a UNC path? things I came across suggests this can work - something like?: $dir = opendir(""your.ip.add.ress\\your_share""); > ... > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Windows directory listings
> -Original Message- > From: Jochem Maas [mailto:[EMAIL PROTECTED] > Sent: January 7, 2007 8:35 PM > To: Beauford > Cc: 'PHP' > Subject: Re: [PHP] 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].""; } > > > > > > > > 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 ''; > var_dump($path, is_dir($path), is_readable($path)); echo ''; 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 > '') - 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:[EMAIL PROTECTED] > >> Sent: January 7, 2007 10:25 AM > >> To: Beauford > >> Cc: PHP > >> Subject: Re: [PHP] 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
Re: [PHP] 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].""; } > > > > 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. 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 ''; var_dump($path, is_dir($path), is_readable($path)); echo ''; 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 '') - 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:[EMAIL PROTECTED] >> Sent: January 7, 2007 10:25 AM >> To: Beauford >> Cc: PHP >> Subject: Re: [PHP] 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
RE: [PHP] Windows directory listings
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"; // $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 ) ; } ?> > -Original Message- > From: Jochem Maas [mailto:[EMAIL PROTECTED] > Sent: January 7, 2007 10:25 AM > To: Beauford > Cc: PHP > Subject: Re: [PHP] 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
Re: [PHP] 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] Windows directory listings
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 structure. Is there another way to do this. Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php