用PHP寫的一個HTTP下載類

來源:互聯網
上載者:User

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.