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

php中文网
发布: 2016-07-13 17:41:17
原创
968人浏览过

功能比较全的下载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 "具体返回头:
    ";
  77.                 foreach($this->m_httphead as $k=>$v)
  78.                 {
  79.            &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...
相关标签:
php
PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号