PHP探测要下载的文件大小

function getsize($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.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))
                    { 
                        $size=trim($arr[1]); 
                        return $size;
                    } 
            }
			
		}
		else
		{
			exit('不支持fsockopen或地址失效:'.$error);
		}
	}



你可能感兴趣的:(PHP探测要下载的文件大小)