[Scummvm-devel] [Scummvm-cvs-logs] SF.net SVN: scummvm:[40038] web/trunk/downloads.php
J. King
jking at jkingweb.ca
Tue Apr 21 17:06:50 CEST 2009
On Tue, 21 Apr 2009 07:52:36 -0400, Travis Howell <kirben at optusnet.com.au>
wrote:
> I'm not familiar with php scripting, so I didn't notice until commit. I
> was hoping another method could be used, so people could tell when
> exactly the last snapshots were generated, and the expected download
> size.
Yeah, the HTTP wrapper doesn't support stat() functionality, so you can't
get filesize() or filemtime() results (even though such data is usually
available via a HEAD request in HTTP, at least on static resources. You
can, under normal circumstances, get the desired data, but it's rather on
the convoluted side:
function url_get_meta($url) {
$stream = fopen($url, "r", 0,
stream_context_create(array('http' => array('method' => "HEAD"))));
$header = stream_get_meta_data($stream);
// We reverse because headers stack after redirections
$header = array_reverse($header['wrapper_data']);
fclose($stream);
for ($a = 0; $a < sizeof($header); $a++) {
if (preg_match("/^Last-Modified:\s+(.+)$/i", $header[$a], $match)) {
$time = date("F j, Y, g:i a", strtotime($match[1]));
break;
}
}
for ($a = 0; $a < sizeof($header); $a++) {
if (preg_match("/^Content-Length:\s+(\d+)$/i", $header[$a], $match)) {
$size = ceil($match[1] / 1024);
break;
}
}
return array('size' => $size, 'time' => $time);
}
The amount of processing involved is a little much for advisory data,
unfortunately. There may be a better way, but if there is I've yet to
find it---which is unfortunate since this sort of thing has been a common
use case in my experience.
--
J. King
More information about the Scummvm-devel
mailing list