澳门游戏平台大全 澳门十大电子游戏平台 php获取远程图片体积大小的实例_php实例_脚本之家

php获取远程图片体积大小的实例_php实例_脚本之家

澳门十大电子游戏平台,直接看代码吧,很好明白的复制代码
代码如下://用法 echo remote_filesize;$url =

remote_filesize;

function remote_filesize{// start output buffering ob_start();//
initialize curl with given uri $ch = curl_init; // 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 { $headers = array(‘Authorization: Basic ‘ .
base64_encode; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); }
$okay = curl_exec; // 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:ss/’; $count = preg_match($regex, $head,
$matches); // if there was a Content-Length field, its value // will now
be in $matches[1] if { $size = $matches[1]; } else { $size =
‘unknown’; } $last_mb = round;$last_kb = round; return $last_kb . ‘KB
/ ‘ . $last_mb.’
MB’;}函数的思路是,先CURL获取图片到缓冲区,然后正则获取图片的Content-Length信息就OK了。

标签:, , , ,

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图