|
Posted by Janwillem Borleffs on 02/01/07 11:19
Eric Layman schreef:
> According to the PHP documentation:
>
> it stated that as of php5, filesize supports the reading of remote html
> files:
>
> http://php.net/manual/en/function.filesize.php
>
It also states that you should look in the HTTP wrapper section of the
appendix to see if it's supported by the stat() function. Like this
function, filesize() only works on local files and doesn't support the
HTTP protocol.
If you want to check the size of a remote file, you could do something
as follows:
$fp = fsockopen('www.google.com', 80);
fputs($fp, "HEAD / HTTP/1.0\r\n");
fputs($fp, "Host: www.google.com\r\n\r\n");
$size = 0;
while (!feof($fp)) {
$line = fgets($fp, 1024);
if (preg_match('/content-length:\s*(\d+)/i', $line, $m)) {
$size = $m[1];
break;
}
}
fclose($fp);
print "Size of Google homepage HTML: $size bytes";
JW
[Back to original message]
|