PHP ftp_nlist时间戳

时间:2016-10-19 13:06:44

标签: php ftp

我想知道在使用ftp_nlist()时是否可以添加文件创建/更新的时间戳。

我的代码现在:

function ftp_get_recursive_paths($conn, $path, $max_level = 0){
    $files = array();
    if($max_level < 0) return $files;
    if($path !== '/' && $path[strlen($path) - 1] !== '/') $path .= '/';
    $files_list = ftp_nlist($conn, $path);

    foreach($files_list as $f){
        if($f !== '.' && $f !== '..' && $f !== $path){
            if(strpos($f, '.') === FALSE){
                $files[$f] = ftp_get_recursive_paths($conn, $f, $max_level-1);
            }else{
                $files[] = basename($f);
            }    
        }
    }

    return $files;
}

输出:

(
    [/folder1] => (
            [0] => file.php
            [1] => file2.php
        )

    [/folder2] => (
            [/folder2/2] => (
                )

        )

)

1 个答案:

答案 0 :(得分:1)

Try with the following code:

function ftp_get_recursive_paths($conn, $path, $max_level = 0){
    $files = array();
    if($max_level < 0) return $files;
    if($path !== '/' && $path[strlen($path) - 1] !== '/') $path .= '/';
    $files_list = ftp_nlist($conn, $path);

    foreach($files_list as $f){
        if($f !== '.' && $f !== '..' && $f !== $path){
            if(strpos($f, '.') === FALSE){
                $files[$f] = ftp_get_recursive_paths($conn, $f, $max_level-1);
            }else{
                $mdate = ftp_mdtm($conn, $f);
                $files[] = basename($f) . " - " . date("m-d-Y H:i:s.", $mdate);
            }    
        }
    }

    return $files;
}