Edit report at https://bugs.php.net/bug.php?id=64024&edit=1

 ID:                 64024
 Updated by:         dtajchre...@php.net
 Reported by:        wowkise at gmail dot com
 Summary:            ftp_dir_exists()
 Status:             Open
 Type:               Feature/Change Request
 Package:            FTP related
 Operating System:   Linux
 PHP Version:        Irrelevant
-Assigned To:        
+Assigned To:        dtajchreber
 Block user comment: N
 Private report:     N

 New Comment:

If the ftpd supports MLST, you can use ftp_raw() to send the command. But I'd 
also 
like to see this implemented as well. 

[1] http://tools.ietf.org/html/rfc3659#page-23
[2] http://us1.php.net/ftp_raw


Previous Comments:
------------------------------------------------------------------------
[2013-01-18 15:28:39] wowkise at gmail dot com

Description:
------------
I think PHP needs proper way to check if the FTP directory exists, right now 
there is no correct way to do it other then using ftp_chdir/is_dir and check 
the results which produce E_WARNING if the directory doesn't exists.

there is also is_dir() function which require that you re-authenticate just to 
check if the directory exists and if you have to check multiple directories you 
have to re-authenticate each time.

i hacked this function in "test script" just to bypass the E_WARNING 

Test script:
---------------
function dir_exists2($conn, $dir) {
    $orginal = $dir;
    if ( !$conn )
        return false;

    if ( substr($dir, -1) === '/' )
        $dir = substr($dir, 0, strlen($dir)-1);

    $dir    = substr($dir, 0, strlen($dir)-strlen(strrchr($dir,'/')));

    $res  = ftp_nlist($conn, '-dF '. $dir);
    if ( isset($res) AND is_array($res) ) {
            foreach ($res as $key => $value) {
                if ($value === $orginal)
                    return true;
            }
        }
        return false;
    }

Expected result:
----------------
true if directory exists and false if it does not exists.



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=64024&edit=1

Reply via email to