• 技术文章 >php教程 >php手册

    PHP编写的HTTP下载类代码

    2016-06-13 10:40:09原创322
    功能比较全的下载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 = "//m.sbmmt.com/m/";
    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 = "//m.sbmmt.com/m/";
    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
      声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
      上一篇:随机现在文章功能之PHP array_rand()函数 下一篇:PHP之isset()与empty()函数区别介绍
    VIP课程(WEB全栈开发)

    相关文章推荐

    • 【活动】充值PHP中文网VIP即送云服务器• Sajax融合服务器端的PHP和JS• 究竟是什么令微软为Windows改进PHP• 简化的实现方法(限制为同一会话页面)• yii2分页的使用及其扩展• PHP页面转UTF-8中文编码乱码的解决办法
    1/1

    PHP中文网