读取图片字节大小

时间:2018-09-07 11:40:00   收藏:0   阅读:268
    //获取图片大小
public function getimgweight(){

$url = ‘http://cdn.caomall.net/1536240025614144138.jpeg‘;
$len = $this->getUriLen($url);
echo $len;exit;
}

function getUriLen($uri,$user=‘‘,$pw=‘‘)
{
ob_start();

$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1); //nobody是关键
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);

$head = ob_get_contents();
ob_end_clean();

$regex = ‘/Content-Length:\s+(.+)/‘;
preg_match($regex, $head, $matches);

// print_r("<pre>");
// print_r ($head);
// print_r ($matches);
// print_r("</pre>");

return $matches[1];
}

原文:https://www.cnblogs.com/pansidong/p/9603525.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!