note 15729 added to function.filesize
| From: | whowd at truman dot edu | Date: | Fri, 28 Sep 2001 05:57:41 +0000 |
| Subject: | note 15729 added to function.filesize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-18403@lists.php.net to get a copy of this message | ||
This is a function to return the remote file size of a file on a HTTP 1.1 server. Use it like this:
$filesize = returnRemoteFilesize("http://www.php.net/links.php");
function returnRemoteFilesize($url) {
$firstCut = substr($url, 7, strlen($url));
$firstSlashPOS = strpos($firstCut, "/");
$host = substr($firstCut, 0, $firstSlashPOS);
$filename = substr($firstCut, $firstSlashPOS, strlen($firstCut));
$fp = fsockopen ($host, 80);
fputs ($fp, "GET $filename HTTP/1.1\r\nHost: jboy.dyn.dhs.org\r\n\r\n");
for($i=0; $i < 10; $i++) {
$buffer .= fgets ($fp,2000);
}
if(strstr($buffer, "Content-Type")) {
fputs ($fp, "\r\n\r\n\r\n");
fclose ($fp);
}
$contentLengthPOS = strpos($buffer, "Content-Length");
$buffer = substr($buffer, $contentLengthPOS+16);
$newLinePOS = strpos($buffer, "\n");
$buffer = substr($buffer, 0, $newLinePOS);
$answer = sprintf("%".strpos($buffer,
".").".1f",$buffer/1024);
if($answer > 1024) {
$answer = sprintf("%".strpos($answer,
".").".1fmb",$answer/1024);
} else {
$answer .= "kb";
}
$formatAnswer = removeWhiteSpace($answer);
return $formatAnswer;
}
--
http://www.php.net/manual/en/function.filesize.php
http://master.php.net/manage/user-notes.php?action=edit+15729
http://master.php.net/manage/user-notes.php?action=delete+15729
http://master.php.net/manage/user-notes.php?action=reject+15729