NukeViet\Ftp\Ftp::detectFtpRoot PHP Method

detectFtpRoot() public method

public detectFtpRoot ( mixed $list_valid = [], string $path_root = '', boolean $read_buffer = true, string $read_file = 'index.php' )
$list_valid mixed
$path_root string
$read_buffer boolean
$read_file string
    public function detectFtpRoot($list_valid = array(), $path_root = '', $read_buffer = true, $read_file = 'index.php')
    {
        if (!$this->check_login()) {
            return false;
        }
        $cwd = $this->pwd();
        $cwd = rtrim($cwd, '/');
        $list_folder = $this->listDetail(null, 'folders');
        if (empty($list_folder)) {
            return false;
        }
        // Chi lay ten thu muc
        for ($i = 0, $n = sizeof($list_folder); $i < $n; ++$i) {
            $list_folder[$i] = $list_folder[$i]['name'];
        }
        if (!is_array($list_valid)) {
            $list_valid = array($list_valid);
        }
        $paths = array();
        // Neu cac file kiem tra dat ngay thu muc dang tro den
        if (sizeof(array_diff($list_valid, $list_folder)) == 0) {
            $paths[] = $cwd . '/';
        }
        // Tim kiem cac thu muc khac tro den duong dan chi dinh
        $parts = explode('/', $path_root);
        $tmp = '';
        for ($i = sizeof($parts) - 1; $i >= 0; --$i) {
            $tmp = '/' . $parts[$i] . $tmp;
            if (in_array($parts[$i], $list_folder)) {
                $paths[] = $cwd . $tmp;
            }
        }
        if ($read_buffer === true) {
            $return_path = false;
            $check_value = file_get_contents($path_root . '/' . $read_file);
            foreach ($paths as $tmp) {
                $filePath = rtrim($tmp, '/') . '/' . $read_file;
                $buffer = null;
                $this->read($filePath, $buffer);
                if ($buffer == $check_value) {
                    $return_path = $tmp;
                    break;
                }
            }
            return $return_path;
        } else {
            return $paths[0];
        }
    }