怎么在php中獲取遠(yuǎn)程圖片的體積大小-創(chuàng)新互聯(lián)

怎么在php中獲取遠(yuǎn)程圖片的體積大???相信很多沒有經(jīng)驗的人對此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。

創(chuàng)新互聯(lián)建站于2013年成立,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項目做網(wǎng)站、網(wǎng)站設(shè)計網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元鳳慶做網(wǎng)站,已為上家服務(wù),為鳳慶各地企業(yè)和個人服務(wù),聯(lián)系電話:18980820575

 代碼如下:



//用法 echo remote_filesize($url,$user='',$pw='');
$url = "/tupian/20230522/404.html remote_filesize($url,$user='',$pw='');

function remote_filesize($uri,$user='',$pw='')
{
// start output buffering
    ob_start();
// initialize curl with given uri
    $ch = curl_init($uri); // make sure we get the header
    curl_setopt($ch, CURLOPT_HEADER, 1); // make it a http HEAD request
    curl_setopt($ch, CURLOPT_NOBODY, 1); // if auth is needed, do it here
    if (!empty($user) && !empty($pw))
    {
        $headers = array('Authorization: Basic ' . base64_encode($user.':'.$pw));
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    }
    $okay = curl_exec($ch);
    curl_close($ch); // get the output buffer
    $head = ob_get_contents(); // clean the output buffer and return to previous // buffer settings
    ob_end_clean();  // gets you the numeric value from the Content-Length // field in the http header
    $regex = '/Content-Length:\s([0-9].+?)\s/';
    $count = preg_match($regex, $head, $matches);  // if there was a Content-Length field, its value // will now be in $matches[1]
    if (isset($matches[1]))
    {
        $size = $matches[1];
    }
    else
    {
        $size = 'unknown';
    }
    $last_mb = round($size/(1024*1024),3);
 $last_kb = round($size/1024,3);
    return $last_kb . 'KB / ' . $last_mb.' MB';
}




看完上述內(nèi)容,你們掌握怎么在php中獲取遠(yuǎn)程圖片的體積大小的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!

分享標(biāo)題:怎么在php中獲取遠(yuǎn)程圖片的體積大小-創(chuàng)新互聯(lián)
文章源于:http://muchs.cn/article46/cdcceg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站、做網(wǎng)站、外貿(mào)建站、企業(yè)網(wǎng)站制作、響應(yīng)式網(wǎng)站、網(wǎng)頁設(shè)計公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

微信小程序開發(fā)