On Fri, Jan 18, 2013 at 9:26 PM, tamouse mailing lists
<tamouse.li...@gmail.com> wrote:
> On Fri, Jan 18, 2013 at 9:43 AM, Daniel Brown <danbr...@php.net> wrote:
>> On Fri, Jan 18, 2013 at 10:33 AM, KISE <wowk...@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.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to