//获取图片大小
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];
}

相关文章:

  • 2022-01-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-17
  • 2022-12-23
  • 2021-06-09
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-13
  • 2021-11-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案