获取远程文件大小的php函数_PHP教程

WBOY
Release: 2016-07-21 15:41:19
Original
862 people have browsed it

复制代码 代码如下:

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;
}else if(preg_match('/Content-Length:(.*)/si',$tmp,$arr)){
return trim($arr[1]);
}
}
return null;
}else{
return null;
}
}
//调用方法
echo getFileSize("http://www.jb51.net/images/logo.gif")
?>

大家运行后,大小应该是4445字节。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/321208.htmlTechArticle复制代码 代码如下: ?php function getFileSize($url){ $url = parse_url($url); if($fp = @fsockopen($url['host'],empty($url['port'])?80:$url['port'],$error)){ fputs($fp,"GET "....
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!