Original geschrieben von Quetschi
-mit doppelten Zeilenumbruch (\r\n\r\n) abschließen.
-mit doppelten Zeilenumbruch (\r\n\r\n) abschließen.
$fp = fsockopen('www.schnabbeldi.de',80, $errno, $error,5)OR die($error."(".$errno.")");
$req = "HEAD /pups.mp3 HTTP/1.1\r\n";
$req .= "Host: www.schnabbeldi.de'\r\n\r\n";
$req .= "Connection: close\r\n\r\n";
fwrite($fp, $req);
while(!feof($fp)) {
$buffer = fread($fp, 1025);
$buffer = str_replace("\r\n", '<br>'."\n", $buffer);
}
fclose($fp);
$HTTPrequ = explode("<br>",$buffer); // in array splitten
echo substr($HTTPrequ[6],16,50); // wert 7 beschnippeln
// und ausgabe der dateigröße
<?php
function remote_filesize($uri, $verbose = FALSE) {
$p_uri = parse_url($uri);
if (empty($p_uri['host'])) return FALSE;
if (empty($p_uri['port'])) $p_uri['port'] = 80;
$fp = fsockopen($p_uri['host'], $p_uri['port'], $errno, $error, 5)
or die($error."(".$errno.")");
if (!isset($p_uri['path']) || $p_uri['path'] == '/')
$req = '/';
else
$req = substr($uri, strpos($uri, $p_uri['path']));
$req = "HEAD $req HTTP/1.1\r\n"
."Host: {$p_uri['host']}\r\n"
."Connection: close\r\n"
."\r\n";
if ($verbose != FALSE)
echo '<b>SEND:</b>'
."(to {$p_uri['host']}:{$p_uri['port']})"
."<pre>$req</pre>";
fwrite($fp, $req);
$buf = '';
while (!feof($fp)) $buf .= fread($fp, 1025);
fclose($fp);
if ($verbose != FALSE)
echo "<b>RECV:</b><pre>$buf</pre>";
if (($pos = strpos($buf, 'Content-Length: ')) !== FALSE) {
return (int)substr($buf,
$pos+strlen('Content-Length: '),
strpos(substr($buf, $pos), "\r\n")
);
}
return FALSE;
}
?>
function remotesize($URL){
$array_url = parse_url($URL); // URL in seine Bestandtteile zerlegen
$fp = fsockopen($array_url[host],80, $errno, $error,5)OR die($error."(".$errno.")");
// header-request an "www.xxx.de"
$req = "HEAD ".$array_url[path]." HTTP/1.1\r\n"; // pfad zur datei
$req .= "Host:".$array_url[host]."\r\n\r\n"; // host "www.xxx.de"
$req .= "Connection: close\r\n\r\n"; // verbindung schliessen
fwrite($fp, $req); // request string in socket schreiben
while(!feof($fp)){ // bis ende des replies
$buffer = fread($fp, 1025); // 1025 bytes lesen
$buffer = str_replace("\r\n", "<br>\n", $buffer); // html zeilenumbrüche erzeugen
}
fclose($fp); // datei schliessen
return (int)substr($buffer,strpos($buffer, "Content-Length: ")+16,7 );
// aus string filesize lesen,nach int casten und weg damit...
}
Kommentar