/** * http下载文件 * * Reads a file and send a header to force download it. * * @access public * * @param string $file 文件路径 * @param string $rename 文件重命名后的名称 * * @return void */ public static function render($file, $rename = null) { //参数分析 if (!$file) { return false; } if (headers_sent()) { return false; } //分析文件是否存在 if (!is_file($file)) { Controller::showMsg('Error 404:The file not found!'); } //分析文件名 $filename = !$rename ? basename($file) : $rename; header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header("Content-Disposition: attachment; filename=\"{$filename}\""); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); ob_clean(); flush(); readfile($file); exit; }
/** * 连接FTP服务器 * * @access public * * @param string $server FTP服务器地址 * @param integer $port FTP服务器端口 * @param string $username FTP用户名 * @param string $password FTP密码 * * @return boolean */ public function connect($server, $port = 21, $username, $password) { //参数分析 if (!$server || !$username || !$password) { return false; } try { $this->_linkId = @ftp_connect($server, $port); if (!@ftp_login($this->_linkId, $username, $password)) { Controller::showMsg('Ftp Server 登陆失败'); } //打开被动模拟 ftp_pasv($this->_linkId, 1); return true; } catch (Exception $exception) { //抛出异常信息 throw new DoitException('Ftp server connect error!<br/>' . $exception->getMessage(), $exception->getCode()); } }