HTTP download code written in PHP

Source: Internet
Author: User

Download the http Resource class with comprehensive functions and obtain the http header information.

  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. // Initialize the system
  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. If (! Empty ($ urls ["user"]) {
  29. $ This-> m_user = $ urls ["user"];
  30. }
  31. If (! Empty ($ urls ["pass"]) {
  32. $ This-> m_pass = $ urls ["pass"];
  33. }
  34. If (! Empty ($ urls ["port"]) {
  35. $ This-> m_port = $ urls ["port"];
  36. }
  37. If (! Empty ($ urls ["path"]) $ this-> m_path = $ urls ["path"];
  38. $ This-> m_urlpath = $ this-> m_path;
  39. If (! Empty ($ urls ["query"])
  40. {
  41. $ This-> m_query = $ urls ["query"];
  42. $ This-> m_urlpath. = "? ". $ This-> m_query;
  43. }
  44. }
  45. }
  46. // Open the specified URL
  47. Function OpenUrl ($ url)
  48. {
  49. // Reset Parameters
  50. $ This-> m_url = "";
  51. $ This-> m_urlpath = "";
  52. $ This-> m_scheme = "http ";
  53. $ This-> m_host = "";
  54. $ This-> m_port = "80 ";
  55. $ This-> m_user = "";
  56. $ This-> m_pass = "";
  57. $ This-> m_path = "/";
  58. $ This-> m_query = "";
  59. $ This-> m_error = "";
  60. $ This-> m_httphead = "";
  61. $ This-> m_html = "";
  62. $ This-> Close ();
  63. // Initialize the system
  64. $ This-> PrivateInit ($ url );
  65. $ This-> PrivateStartSession ();
  66. }
  67. // Obtain the cause of an operation Error
  68. Function printError ()
  69. {
  70. Echo "error message:". $ this-> m_error;
  71. Echo "specific return headers: <br> ";
  72. Foreach ($ this-> m_httphead as $ k => $ v)
  73. {
  74. & Nb

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.