NukeViet\Ftp\Ftp::listDetail PHP Method

listDetail() public method

public listDetail ( mixed $path = null, string $type = 'raw', $show_hidden = false )
$path mixed
$type string
    public function listDetail($path = null, $type = 'raw', $show_hidden = false)
    {
        if (!$this->check_login()) {
            return false;
        }
        // Bat passive mode
        if (ftp_pasv($this->conn_id, true) === false) {
            $this->error = NV_FTP_ERR_PASSIVE_ON;
            return false;
        }
        // Danh sach chi tiet thu muc
        $cmd_path = $show_hidden ? '-al ' . $path : $path;
        $list_detail = ftp_rawlist($this->conn_id, $cmd_path);
        if ($list_detail === false) {
            $this->error = NV_FTP_ERR_RAWLIST;
            return false;
        }
        $dir_list = array();
        if ($type == 'raw') {
            return $list_detail;
        }
        if (empty($list_detail[0])) {
            return $dir_list;
        }
        if (strtolower(substr($list_detail[0], 0, 6)) == 'total ') {
            array_shift($list_detail);
            if (!isset($list_detail[0]) or empty($list_detail[0])) {
                return $dir_list;
            }
        }
        // Xac dinh chuan dinh dang cua 3 he dieu hanh
        $regexps = array('UNIX' => '#([-dl][rwxstST-]+).* ([0-9]*) ([a-zA-Z0-9]+).* ([a-zA-Z0-9]+).* ([0-9]*) ([a-zA-Z]+[0-9: ]*[0-9])[ ]+(([0-9]{1,2}:[0-9]{2})|[0-9]{4}) (.+)#', 'MAC' => '#([-dl][rwxstST-]+).* ?([0-9 ]*)?([a-zA-Z0-9]+).* ([a-zA-Z0-9]+).* ([0-9]*) ([a-zA-Z]+[0-9: ]*[0-9])[ ]+(([0-9]{2}:[0-9]{2})|[0-9]{4}) (.+)#', 'WIN' => '#([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|<DIR>) +(.+)#');
        // Xac dinh he dieu hanh thich hop
        $osType = null;
        foreach ($regexps as $k => $v) {
            if (preg_match($v, $list_detail[0])) {
                $osType = $k;
                $regexp = $v;
                break;
            }
        }
        if (!$osType) {
            $this->error = NV_FTP_ERR_LISTDETAIL_NOTRECONIZE;
            return false;
        }
        if ($osType == 'UNIX') {
            foreach ($list_detail as $file) {
                $tmp_array = null;
                if (preg_match($regexp, $file, $regs)) {
                    $fType = (int) strpos('-dl', $regs[1][0]);
                    $tmp_array['type'] = $fType;
                    $tmp_array['rights'] = $regs[1];
                    $tmp_array['user'] = $regs[3];
                    $tmp_array['group'] = $regs[4];
                    $tmp_array['size'] = $regs[5];
                    $tmp_array['date'] = strtotime($regs[6]);
                    $tmp_array['time'] = $regs[7];
                    $tmp_array['name'] = $regs[9];
                }
                if ($type != 'all') {
                    if ($type == 'files' and $tmp_array['type'] == 1) {
                        continue;
                    }
                    if ($type == 'folders' and $tmp_array['type'] == 0) {
                        continue;
                    }
                }
                if (is_array($tmp_array) and $tmp_array['name'] != '.' and $tmp_array['name'] != '..') {
                    $dir_list[] = $tmp_array;
                }
            }
        } elseif ($osType == 'MAC') {
            foreach ($list_detail as $file) {
                $tmp_array = null;
                if (preg_match($regexp, $file, $regs)) {
                    $fType = (int) strpos('-dl', $regs[1][0]);
                    $tmp_array['type'] = $fType;
                    $tmp_array['rights'] = $regs[1];
                    $tmp_array['user'] = $regs[3];
                    $tmp_array['group'] = $regs[4];
                    $tmp_array['size'] = $regs[5];
                    $tmp_array['date'] = strtotime($regs[6]);
                    $tmp_array['time'] = $regs[7];
                    $tmp_array['name'] = $regs[9];
                }
                if ($type != 'all') {
                    if ($type == 'files' and $tmp_array['type'] == 1) {
                        continue;
                    }
                    if ($type == 'folders' and $tmp_array['type'] == 0) {
                        continue;
                    }
                }
                if (is_array($tmp_array) and $tmp_array['name'] != '.' and $tmp_array['name'] != '..') {
                    $dir_list[] = $tmp_array;
                }
            }
        } else {
            foreach ($list_detail as $file) {
                $tmp_array = null;
                if (preg_match($regexp, $file, $regs)) {
                    $fType = (int) ($regs[7] == '<DIR>');
                    $timestamp = strtotime("{$regs['3']}-{$regs['1']}-{$regs['2']} {$regs['4']}:{$regs['5']}{$regs['6']}");
                    $tmp_array['type'] = $fType;
                    $tmp_array['rights'] = '';
                    $tmp_array['user'] = '';
                    $tmp_array['group'] = '';
                    $tmp_array['size'] = (int) $regs[7];
                    $tmp_array['date'] = $timestamp;
                    $tmp_array['time'] = $timestamp;
                    $tmp_array['name'] = $regs[8];
                }
                if ($type != 'all') {
                    if ($type == 'files' and $tmp_array['type'] == 1) {
                        continue;
                    }
                    if ($type == 'folders' and $tmp_array['type'] == 0) {
                        continue;
                    }
                }
                if (is_array($tmp_array) and $tmp_array['name'] != '.' and $tmp_array['name'] != '..') {
                    $dir_list[] = $tmp_array;
                }
            }
        }
        return $dir_list;
    }