在php中,下载http资源比较常用的一种做法就是用 file_get_contents 这个函数,但这函数无法获得http头的信息,会给一些应用带来不方便,因此我写了一个http下载类来解决这个问题,测试感觉速度和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 = "";
//
//初始化系统
//
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;
}
}
}
//
//打开指定网址
//
function OpenUrl($url)
{
//重设各参数
$this->m_url = "";
$this->m_urlpath = "";
$this->m_scheme = "http";
$this->m_host = "";