Reply to Re: obtaining the size of a file

Your name:

Reply:


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

[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

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