读取远程文件大小
<?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.1rn");
fputs($fp, "Host:$url[host]rnrn");
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://127.0.0.67/chinaz.rar");永久链接:http://www.phprm.com/code/78042cd953f7ac75dce53f84a0be6aa2.html
转载随意!带上文章地址吧。