PHP编写的HTTP下载类代码_PHP教程
时间:2021-07-01 10:21:17
帮助过:2人阅读
功能比较全的下载http资源类,同时可以获得http头的信息。
- class DedeHttpDown
- {
- public $m_url = "";
- public $m_urlpath = "";
- public $m_scheme = "http";
- public $m_host = "";
- public $m_port = "80";
- public $m_user = "";
- public $m_pass = "";
- public $m_path = "/";
- public $m_query = "";
- public $m_fp = "";
- public $m_error = "";
- public $m_httphead = "" ;
- public $m_html = "";
-
- //初始化系统
- function PrivateInit($url)
- {
- $urls = "";
- $urls = @parse_url($url);
- $this->m_url = $url;
- if(is_array($urls))
- {
- $this->m_host = $urls["host"];
- if(!empty($urls["scheme"])) $this->m_scheme = $urls["scheme"];
-
- if(!empty($urls["user"])){
- $this->m_user = $urls["user"];
- }
-
- if(!empty($urls["pass"])){
- $this->m_pass = $urls["pass"];
- }
-
- if(!empty($urls["port"])){
- $this->m_port = $urls["port"];
- }
-
- if(!empty($urls["path"])) $this->m_path = $urls["path"];
- $this->m_urlpath = $this->m_path;
-
- if(!empty($urls["query"]))
- {
- $this->m_query = $urls["query"];
- $this->m_urlpath .= "?".$this->m_query;
- }
- }
- }
- //打开指定网址
- function OpenUrl($url)
- {
- //重设各参数
- $this->m_url = "";
- $this->m_urlpath = "";
- $this->m_scheme = "http";
- $this->m_host = "";
- $this->m_port = "80";
- $this->m_user = "";
- $this->m_pass = "";
- $this->m_path = "/";
- $this->m_query = "";
- $this->m_error = "";
- $this->m_httphead = "" ;
- $this->m_html = "";
- $this->Close();
- //初始化系统
- $this->PrivateInit($url);
- $this->PrivateStartSession();
- }
- //获得某操作错误的原因
- function printError()
- {
- echo "错误信息:".$this->m_error;
- echo "具体返回头:
"; - foreach($this->m_httphead as $k=>$v)
- {
- &nb
http://www.bkjia.com/PHPjc/486141.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/486141.htmlTechArticle功能比较全的下载http资源类,同时可以获得http头的信息。 ?php class DedeHttpDown { public $m_url = ""; public $m_urlpath = ""; public $m_scheme = "http"; public...