php4如何获取远程文件大小类

作者:袖梨 2022-06-24

 /*
 
 */

 代码如下 复制代码

if(!function_exists('get_headers'))
{
    function get_headers($url,$format=0)
    {
        $url=parse_url($url);
        $end = " ";
        $fp = fsockopen($url['host'], (empty($url['port'])?80:$url['port']), $errno, $errstr, 30);
        if ($fp)
        {
            $out  = "get / http/1.1 ";
            $out .= "host: ".$url['host']." ";
            $out .= "connection: close ";
            $var  = '';
            fwrite($fp, $out);
            while (!feof($fp))
            {
                $var.=fgets($fp, 1280);
                if(strpos($var,$end))
                    break;
            }
            fclose($fp);

            $var=preg_replace("/ .*$/",'',$var);
            $var=explode(" ",$var);
            if($format)
            {
                foreach($var as $i)
                {
                    if(preg_match('/^([a-za-z -]+): +(.*)$/',$i,$parts))
                        $v[$parts[1]]=$parts[2];
                }
                return $v;
            }
            else
                return $var;
        }
    }
}

相关文章

精彩推荐