php怎么获取远程压缩包rar的大小。默认的函数filesize可以获取文本大小,但是获取不了rar文件,
小编网站有下载模块,自带的phpcms这个功能有问题,不能获取文件大小。小编就需要二开了。下面是获取远程文件大小
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; } } //调试一下 $size = getFileSize('http://127.0.0.1/test/uploadfile/2018/0409/20180409050617769.rar'); echo "original size: $size bytes\n";
代码运行ok。