|
Posted by Janwillem Borleffs on 02/26/06 13:12
Steve wrote:
> Hmm, could you make a HEAD request? That has a content size header,
> although I don't know if you'd have to factor in the size of the
> header itself and whether any encoding is used.
>
Sure, per ezample:
$host = 'www.google.com';
$path = '/images/logo.gif';
$bytes = 0;
if ($fp = fsockopen($host, 80)) {
fputs($fp, "HEAD $path HTTP/1.0\r\n");
fputs($fp, "Host: $host\r\n\r\n");
while (!feof($fp) && !$bytes) {
if (preg_match('/content\-length\s*:\s*(\d+)/i',
fgets($fp, 1024),
$m)) {
$bytes = $m[1];
}
}
fclose($fp);
}
print "size is $bytes bytes";
JW
Navigation:
[Reply to this message]
|