Copy code The code is as follows:
function getFileSize($url){
$url = parse_url ($url);
if($fp = @fsockopen($url['host'],empty($url['port'])?80:$url['port'],$error)){
fputs($fp,"GET ".(empty($url['path'])?'/':$url['path'])." HTTP/1.1rn");
fputs( $fp,"Host:$url[host]rnrn");
while(!feof($fp)){
$tmp = fgets($fp);
if(trim($tmp) == ''){
break;
}else if(preg_match('/Content-Length:(.*)/si',$tmp,$arr)){
return trim($arr [1]);
}
}
return null;
}else{
return null;
}
}
//Call method
echo getFileSize("http://www.jb51.net/images/logo.gif")
?>
After everyone runs it, the size should be 4445 bytes.
http://www.bkjia.com/PHPjc/321208.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321208.htmlTechArticleCopy the code as follows: ?php function getFileSize($url){ $url = parse_url($url); if ($fp = @fsockopen($url['host'],empty($url['port'])?80:$url['port'],$error)){ fputs($fp,"GET ". ...