标签:header init 图片 mat nts ril public set basic
//获取图片大小
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];
}
标签:header init 图片 mat nts ril public set basic
原文地址:https://www.cnblogs.com/pansidong/p/9603525.html