首页 > 开发 > PHP > 正文

读取远程文件大小

2024-05-04 22:58:54
字体:
来源:转载
供稿:网友

<?php
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.1/r/n");
                fputs($fp,"host:$url[host]/r/n/r/n");
                while(!feof($fp))
    {
                 $tmp = fgets($fp);
                    if(trim($tmp) == '')
     {
                        break;
                    }elseif(preg_match('/content-length:(.*)/si',$tmp,$arr))
     {
                     return trim($arr[1]);
                     }
                }
                return null;
        }else
  {
         return null;
        }
}
echo  getfilesize("http://www.xrss.cn/chinaz.rar");

?>

 

 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表