四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

php獲取遠程圖片體積大小的實例

直接看代碼吧,很好明白的
復制代碼 代碼如下:
//用法 echo remote_filesize($url,$user='',$pw='');
$url = "http://www.aa.com/librarys/images/random/rand_11.jpg";//這里要換成你的圖片地址
echo 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';
}

函數的思路是,先CURL獲取圖片到緩沖區,然后正則獲取圖片的Content-Length信息就OK了。

php技術php獲取遠程圖片體積大小的實例,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 普庵咒全文注音版| 韩国电影陈诗雅主演| 红色娘子军歌词| 色黄视频免费观看| 电影画皮3免费| 十三刺客| 讯息 电影| 保镖1993在线观看| 密探| 大雄的日本诞生| 金马电影网| 台湾卫视| 德川家康的地狱| 禁忌的游戏| 皇冠小刀清痘视频| cctv16体育节目表今天目表| 青春之歌电影演员表名单| 混沌行走| 网络流行歌曲2024最火前十名| 新娘大作战angelababy| 女人的战争剧情介绍| 红旗车驾驶员个人主要事迹材料| 郑艳丽曹查理主演的影片| jakeandrich全见版| tbbt| 一元二次方程计算题| 寡妇一级毛片视频| 甜蜜杀机 电影| 海洋之歌免费观看完整中文版 | 河南省gdp城市排名| 杨幂吻戏| 暴露视频| 高志鹏| 九州电影网| 疯狂试爱四| 张学友电影全部作品| 电影在线观看高清完整版免费| 影视剧分娩片段合集| 色戒在线观看视频| 电影终结之战 电影| 疯狂试爱四|