Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * 连接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());
     }
 }
 /**
  * 抛出异常提示信息处理
  *
  * 用于执行SQL语句时,程序出现异常时的异常信息抛出
  *
  * @access public
  * @return integer
  */
 public function throwException($exception, $sql, $params = array())
 {
     //参数分析
     if (!is_object($exception) || !$sql) {
         return false;
     }
     if (!is_array($params)) {
         $params = func_get_args();
         array_shift($params);
     }
     //获取所执行的SQL语句
     $sql = $this->_parseQuerySql($sql, $params);
     //当调试模式关闭时
     if (DOIT_DEBUG === false) {
         //记录错误日志
         Log::write("SQL execute error! SQL:{$sql} Error Message:" . $exception->getMessage());
         //提示错误信息
         Controller::showMsg('SQL语句执行错误!详细情况请查看日志。');
     }
     //抛出异常信息
     throw new DoitException("SQL execute error!<br/>SQL:{$sql} " . $exception->getMessage());
 }