Код: Выделить всё
function getRemoteSize($url) {
$parsedUrl = parse_url($url);
$host = $parsedUrl['host'];
$path = $parsedUrl['path'];
$ourhead = '';
$fp = fsockopen($host, 80, $errno, $errstr, 20);
if(!$fp) {
exit("$errstr ($errno)
\n");
} else {
$out = "HEAD $url HTTP/1.1\r\n";
$out .= "HOST: dummy\r\n";
$out .= "Connection: close\r\n\r\n";
fputs($fp,$out);
while (!feof($fp)) {
$ourhead = sprintf("%s%s", $ourhead, fgets ($fp,128));
}
}
fclose($fp);
$split1 = explode("content-length: ", strtolower($ourhead));
if(!@$split1[1]) exit('Error: No content length');
$split2 = explode("\r\n", $split1[1]);
$size = (int) $split2[0]; // size in bytes
return $size;
}