时间:2021-07-01 10:21:17 帮助过:21人阅读
/**
* 远程获取文件大小
*/
function getFileSize($url){
$url = parse_url($url);//返回url组成部分关联数组
if($fp = @fsockopen($url['host'],empty($url['port'])?80:$url['port'],$error)){
fputs($fp,"GET ".(empty($url['path'])?'/':$url['path'])." HTTP/1.1\r\n");//
fputs($fp,"Host:$url[host]\r\n\r\n");
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;
}
}以上就介绍了远程获取文件大小,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。