首頁  >  文章  >  後端開發  >  PHP编写的HTTP下载类代码_PHP教程

PHP编写的HTTP下载类代码_PHP教程

WBOY
WBOY原創
2016-07-13 17:41:17849瀏覽

功能比较全的下载http资源类,同时可以获得http头的信息。

  1. class DedeHttpDown
  2. {
  3.         public $m_url = "";
  4.         public $m_urlpath = "";
  5.         public $m_scheme = "http";
  6.         public $m_host = "";
  7.         public $m_port = "80";
  8.         public $m_user = "";
  9.         public $m_pass = "";
  10.         public $m_path = "/";
  11.         public $m_query = "";
  12.         public $m_fp = "";
  13.         public $m_error = "";
  14.         public $m_httphead = "" ;
  15.         public $m_html = "";
  16.  
  17.         //初始化系统
  18.         function PrivateInit($url)
  19.         {
  20.                 $urls = "";
  21.                 $urls = @parse_url($url);
  22.                 $this->m_url = $url;
  23.                 if(is_array($urls))
  24.                 {
  25.                         $this->m_host = $urls["host"];
  26.                         if(!empty($urls["scheme"])) $this->m_scheme = $urls["scheme"];
  27.                     
  28.                         if(!empty($urls["user"])){
  29.                                 $this->m_user = $urls["user"];
  30.                         }
  31.                     
  32.                         if(!empty($urls["pass"])){
  33.                                 $this->m_pass = $urls["pass"];
  34.                         }
  35.                     
  36.                         if(!empty($urls["port"])){
  37.                                 $this->m_port = $urls["port"];
  38.                         }
  39.                 
  40.                         if(!empty($urls["path"])) $this->m_path = $urls["path"];
  41.                         $this->m_urlpath = $this->m_path;
  42.                 
  43.                         if(!empty($urls["query"]))
  44.                         {
  45.                                 $this->m_query = $urls["query"];
  46.                                 $this->m_urlpath .= "?".$this->m_query;
  47.                         }
  48.                 }
  49.         }
  50.         //打开指定网址
  51.         function OpenUrl($url)
  52.         {
  53.                 //重设各参数
  54.                 $this->m_url = "";
  55.                 $this->m_urlpath = "";
  56.                 $this->m_scheme = "http";
  57.                 $this->m_host = "";
  58.                 $this->m_port = "80";
  59.                 $this->m_user = "";
  60.                 $this->m_pass = "";
  61.                 $this->m_path = "/";
  62.                 $this->m_query = "";
  63.                 $this->m_error = "";
  64.                 $this->m_httphead = "" ;
  65.                 $this->m_html = "";
  66.                 $this->Close();
  67.                 //初始化系统
  68.                 $this->PrivateInit($url);
  69.                 $this->PrivateStartSession();
  70.         }
  71.         //获得某操作错误的原因
  72.         function printError()
  73.         {
  74.                 echo "错误信息:".$this->m_error;
  75.                 echo "具体返回头:
    ";
  76.                 foreach($this->m_httphead as $k=>$v)
  77.                 {
  78.            &nb

    www.bkjia.comtruehttp://www.bkjia.com/PHPjc/486141.htmlTechArticle功能比较全的下载http资源类,同时可以获得http头的信息。 ?php class DedeHttpDown { public $m_url = ""; public $m_urlpath = ""; public $m_scheme = "http"; public...
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn