An HTTP download class written in PHP

Source: Internet
Author: User

In PHP, the most common way to download HTTP resources is to use the file_get_contents function, but this function can not get the HTTP header information, will be inconvenient to some applications, so I wrote an HTTP download class to solve this problem, test the sense of speed and file _get_contents.

?
Class Dedehttpdown
{
var $m _url = "";
var $m _urlpath = "";
var $m _scheme = "http";
var $m _host = "";
var $m _port = "80";
var $m _user = "";
var $m _pass = "";
var $m _path = "/";
var $m _query = "";
var $m _fp = "";
var $m _error = "";
var $m _httphead = "";
var $m _html = "";
//
Initializing the system
//
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;
}
}
}
//
Open the specified URL
//
function OpenURL ($url)
{
Reset each parameter
$this->m_url = "";
$this->m_urlpath = "";
$this->m_scheme = "http";
$this->m_host = "";

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.