NukeViet\Ftp\Ftp::__construct PHP Method

__construct() public method

public __construct ( string $host = '', string $user = 'root', string $pass = '', mixed $config = [], integer $port = 21 )
$host string
$user string
$pass string
$config mixed
$port integer
    public function __construct($host = '', $user = 'root', $pass = '', $config = array(), $port = 21)
    {
        // Kiem tra thu vien FTP hoat dong
        $disable_functions = (ini_get('disable_functions') != '' and ini_get('disable_functions') != false) ? array_map('trim', preg_split("/[\\s,]+/", ini_get('disable_functions'))) : array();
        if (extension_loaded('suhosin')) {
            $disable_functions = array_merge($disable_functions, array_map('trim', preg_split("/[\\s,]+/", ini_get('suhosin.executor.func.blacklist'))));
        }
        if (!(extension_loaded('ftp') and (empty($disable_functions) or !empty($disable_functions) and !preg_grep('/^ftp\\_/', $disable_functions)))) {
            $this->error = NV_FTP_ERR_DISABLED_FTP;
            return false;
        }
        unset($disable_functions);
        if (!empty($host)) {
            $this->host = $host;
        }
        if (!empty($user)) {
            $this->user = $user;
        }
        if (!empty($pass)) {
            $this->pass = $pass;
        }
        if (!empty($port)) {
            $this->port = $port;
        }
        // Xac dinh thoi gian het han
        if (!empty($config['timeout']) and $config['timeout'] > 0) {
            $this->config['timeout'] = intval($config['timeout']);
        }
        // Xac dinh phuong thuc
        if (isset($config['type']) and in_array($config['type'], array(FTP_BINARY, FTP_AUTOASCII, FTP_ASCII))) {
            $this->config['type'] = $config['type'];
        }
        // Xac dinh he hieu hanh
        if (!empty($config['os']) and in_array($config['os'], array('WIN', 'UNIX', 'MAC'))) {
            $this->config['os'] = $config['os'];
        } else {
            if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
                $this->config['os'] = 'WIN';
            } elseif (strtoupper(substr(PHP_OS, 0, 3)) === 'MAC') {
                $this->config['os'] = 'MAC';
            } else {
                $this->config['os'] = 'UNIX';
            }
        }
        // Ket noi den FTP server
        if (!is_resource($this->conn_id)) {
            $this->conn_id = ftp_connect($this->host, $this->port);
            if ($this->conn_id === false) {
                $this->error = NV_FTP_ERR_CONNECT;
                return false;
            }
            ftp_set_option($this->conn_id, FTP_TIMEOUT_SEC, $this->config['timeout']);
        }
        // Dang nhap
        if (ftp_login($this->conn_id, $this->user, $this->pass) === false) {
            $this->error = NV_FTP_ERR_LOGIN;
            return false;
        } else {
            $this->logined = true;
        }
    }