Here is a function for returning the uncompressed filesize of a gzip file. The filesize is stored as a 32-bit integer in the end of the compressed file, that's how this function works. Additionally, this function checks to see if it's a real gzip compressed file before doing the work; if it isn't, then just like other gz- functions, it'll treat it just like a regular file and perform a normal filesize operation. Enjoy!
<?php
function gzfilesize($filename) {
$gzfs = FALSE;
if(($zp = fopen($filename, 'r'))!==FALSE) {
if(@fread($zp, 2) == "\x1F\x8B") { fseek($zp, -4, SEEK_END);
if(strlen($datum = @fread($zp, 4))==4)
extract(unpack('Vgzfs', $datum));
}
else $gzfs = filesize($filename);
fclose($zp);
}
return($gzfs);
}
?>