Home  >  Article  >  Backend Development  >  HTTP download code written in PHP_PHP tutorial

HTTP download code written in PHP_PHP tutorial

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

Download http resource class with relatively complete functions and obtain http header information at the same time.

  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...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn