PHP FTP recursive directory listing

前端 未结 3 483
轻奢々
轻奢々 2020-12-10 09:12

I\'m trying to make a recursive function to get all the directories and sub directories from my ftp server in an array.

I tried a lot of functions I\'ve found on the

3条回答
  •  天涯浪人
    2020-12-10 09:59

    This code a variation of Martin Prikryl one. It is slower but do not have any failures with whitespaces. Use this code only if you have any problems with the code above.

    function ftp_list_files_recursive($ftp_stream, $path){
        $lines = ftp_nlist($ftp_stream, $path);
        $result = array();
        foreach ($lines as $line) {
            if (ftp_size($ftp_stream, $line) == -1) {
                $result = array_merge($result, ftp_list_files_recursive($ftp_stream, $line));
            }
            else{
                $result[] = $line;
            }
        }
        return $result;
    }
    

提交回复
热议问题