当前位置:Gxlcms > PHP教程 > PHP编写的HTTP下载类代码_PHP教程

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

时间:2021-07-01 10:21:17 帮助过:2人阅读

功能比较全的下载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. function PrivateInit($url)
  18. {
  19. $urls = "";
  20. $urls = @parse_url($url);
  21. $this->m_url = $url;
  22. if(is_array($urls))
  23. {
  24. $this->m_host = $urls["host"];
  25. if(!empty($urls["scheme"])) $this->m_scheme = $urls["scheme"];
  26. if(!empty($urls["user"])){
  27. $this->m_user = $urls["user"];
  28. }
  29. if(!empty($urls["pass"])){
  30. $this->m_pass = $urls["pass"];
  31. }
  32. if(!empty($urls["port"])){
  33. $this->m_port = $urls["port"];
  34. }
  35. if(!empty($urls["path"])) $this->m_path = $urls["path"];
  36. $this->m_urlpath = $this->m_path;
  37. if(!empty($urls["query"]))
  38. {
  39. $this->m_query = $urls["query"];
  40. $this->m_urlpath .= "?".$this->m_query;
  41. }
  42. }
  43. }
  44. //打开指定网址
  45. function OpenUrl($url)
  46. {
  47. //重设各参数
  48. $this->m_url = "";
  49. $this->m_urlpath = "";
  50. $this->m_scheme = "http";
  51. $this->m_host = "";
  52. $this->m_port = "80";
  53. $this->m_user = "";
  54. $this->m_pass = "";
  55. $this->m_path = "/";
  56. $this->m_query = "";
  57. $this->m_error = "";
  58. $this->m_httphead = "" ;
  59. $this->m_html = "";
  60. $this->Close();
  61. //初始化系统
  62. $this->PrivateInit($url);
  63. $this->PrivateStartSession();
  64. }
  65. //获得某操作错误的原因
  66. function printError()
  67. {
  68. echo "错误信息:".$this->m_error;
  69. echo "具体返回头:
    ";
  70. foreach($this->m_httphead as $k=>$v)
  71. {
  72. &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...

人气教程排行