怎么在php中获取远程图片的体积大小-创新互联
怎么在php中获取远程图片的体积大小?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
创新互联建站于2013年成立,是专业互联网技术服务公司,拥有项目做网站、网站设计网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元凤庆做网站,已为上家服务,为凤庆各地企业和个人服务,联系电话:18980820575代码如下:
//用法 echo remote_filesize($url,$user='',$pw='');
$url = "/tupian/20230522/404.html 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';
}
看完上述内容,你们掌握怎么在php中获取远程图片的体积大小的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!
分享名称:怎么在php中获取远程图片的体积大小-创新互联
文章URL:http://pwwzsj.com/article/cdcceg.html