note 17850 deleted from function.filesize by jimw
| From: | jimw@php.net | Date: | Wed, 02 Jan 2002 11:41:05 +0000 |
| Subject: | note 17850 deleted from function.filesize by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-24232@lists.php.net to get a copy of this message | ||
If you want to get the filesize of a file only accessible by http you can do it like this (it took
me a while to figure it out) ;)
function httpfilesize($url) {
$parts = preg_match('/http:\/\/([a-zA-Z0-9\.-]*)(\/.*)/', $url, $matches);
$buffer = '';
$fp = fsockopen ($matches[1], 80, $errno, $errstr, 30);
if (!$fp) return false;
fputs ($fp, "HEAD ".$matches[2]." HTTP/1.1\r\nHost:
".$matches[1]."\r\n\r\n");
while (!feof($fp)) $buffer .= fgets ($fp,128);
fclose ($fp);
preg_match('/.*Content-Length: ([0-9]*).*/', $buffer, $ret);
return $ret[1];
}