Re: Re: new FTP function
| From: | tamouse mailing lists | Date: | Sat, 19 Jan 2013 03:26:35 +0000 |
| Subject: | Re: Re: new FTP function | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-320095@lists.php.net to get a copy of this message | ||
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.