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 = "";