首页 > 其他 > 详细

读取图片字节大小

时间:2018-09-07 11:40:00      阅读:265      评论:0      收藏:0      [点我收藏+]
    //获取图片大小
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)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!