Heim  >  Artikel  >  Backend-Entwicklung  >  PHP编写的HTTP下载类代码_PHP教程

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

WBOY
WBOYOriginal
2016-07-13 17:41:17849Durchsuche

功能比较全的下载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...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn