Voting

: max(six, four)?
(Example: nine)

The Note You're Voting On

Nitrogen
14 years ago
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") { // this is a gzip'd file
 fseek($zp, -4, SEEK_END);
 if(strlen($datum = @fread($zp, 4))==4)
 extract(unpack('Vgzfs', $datum));
 }
 else // not a gzip'd file, revert to regular filesize function
 $gzfs = filesize($filename);
 fclose($zp);
 }
 return($gzfs);
}
?>

<< Back to user notes page

AltStyle によって変換されたページ (->オリジナル) /