PHP头条
热点:

PHP编写的HTTP下载类代码


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

    www.phpzy.comtrue/phprm/24551.htmlTechArticlePHP编写的HTTP下载类代码 功能比较全的下载http资源类,同时可以获得http头的信息。 ?php class DedeHttpDown { public $m_url = ""; public $m_urlpath = ""; public $m_scheme = "http"; public $m_host = ""; public $m_po...

相关文章

    暂无相关文章

PHP之友评论

今天推荐