Получить размер файла на другом сервере, php
Code (php)
-
-
function remote_file_size ($url){
-
$head = "";
-
$host = $url_p["host"];
-
// a domain name was given, not an IP
-
//domain could not be resolved
-
return -1;
-
}
-
}
-
if(!$port) $port=80;
-
$path = $url_p["path"];
-
//echo "Getting " . $host . ":" . $port . $path . " …";
-
-
if(!$fp) {
-
return false;
-
} else {
-
$headers = "";
-
}
-
}
-
//echo $errno .": " . $errstr . "
-
";
-
$return = -2;
-
$arr_headers = explode("\n", $headers);
-
// echo "HTTP headers for <a href=‘" . $url . "’>…" . substr($url,strlen($url)-20). "</a>:";
-
// echo "<div class=‘http_headers’>";
-
foreach($arr_headers as $header) {
-
// if (trim($header)) echo trim($header) . "
-
";
-
$s1 = "HTTP/1.1";
-
$s2 = "Content-Length: ";
-
$s3 = "Location: ";
-
if(substr(strtolower ($header), 0, strlen($s1)) == strtolower($s1)) $status = substr($header, strlen($s1));
-
if(substr(strtolower ($header), 0, strlen($s2)) == strtolower($s2)) $size = substr($header, strlen($s2));
-
if(substr(strtolower ($header), 0, strlen($s3)) == strtolower($s3)) $newurl = substr($header, strlen($s3));
-
}
-
// echo "</div>";
-
if(intval($size) > 0) {
-
$return=intval($size);
-
} else {
-
$return=$status;
-
}
-
// echo intval($status) .": [" . $newurl . "]
-
";
-
if (intval($status)==302 && strlen($newurl) > 0) {
-
// 302 redirect: get HTTP HEAD of new URL
-
$return=remote_file_size($newurl);
-
}
-
return $return;
-
}
-
-
