Re: Re: new FTP function

From: Date: Sat, 19 Jan 2013 03:58:15 +0000
Subject: Re: Re: new FTP function
References: 1 2 3 4 5 6 7 8  Groups: php.general 
Request: Send a blank email to php-general+get-320096@lists.php.net to get a copy of this message
On Fri, Jan 18, 2013 at 9:26 PM, tamouse mailing lists <tamouse.lists@gmail.com> wrote: > On Fri, Jan 18, 2013 at 9:43 AM, Daniel Brown <danbrown@php.net> wrote: >> On Fri, Jan 18, 2013 at 10:33 AM, KISE <wowkise@gmail.com> wrote: >>> Paul Dragoonis, >>> >>> Actually it wont work i did tried it before, if the dir end with / it will >>> list the directories inside the path you gave it and if it doesn't have any >>> directories it will return false since there is no directories to return. >>> >>> you have to take out the last / and then remove the directory in question >>> and list the files in the parent directory and check if the dir exists >>> otherwise it will return false, i spent 3hrs yesterday thinking why its >>> returning false even though the directory exists. >> >> The discussion is now getting more into the general coding realm >> than internals, so let's move it over there in case anyone wants to >> mention something like: >> >> function ftp_dir_exists($conn, $currentDir) { >> $currentDir = (substr($currentDir,-1,1) == '/') ? >> substr($currentDir,0,-1) : $currentDir; >> $list = ftp_nlist($conn, '-dF '. $currentDir); >> return in_array($currentDir, $list); >> } > > > Haven't played with ftp functions at all, but wondering what if you > gave it dirname($currentDir) instead of $currentDir? (Still have to do > the trailing '/'-ectomy) > > $list = ftp_nlist($conn, dirname($currentDir)); > > untested, just a thought. Although on further thought, if $currentDir actually points to a non-directory, that will still pass, won't it. Might have to go with ftp_rawlist and parse it out to ensure it is a directory... Check the first character of each line to see if it's 'd', then the file name will be the last field in the line.

« previous php.general (#320096) next »