Reply to Re: filesize() not reading http pages

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация