Home > Backend Development > PHP Tutorial > Get file size remotely

Get file size remotely

WBOY
Release: 2016-07-29 09:01:38
Original
1190 people have browsed it
    /**
    *  远程获取文件大小
    */
    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;
        }
    }
Copy after login

Example: getFileSize

The above introduces the remote acquisition of file size, including aspects of content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template