note 110078 added to function.gzread
| From: | Nitrogen | Date: | Mon, 17 Sep 2012 03:03:01 +0000 |
| Subject: | note 110078 added to function.gzread | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-190841@lists.php.net to get a copy of this message | ||
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);
}
?>
----
Server IP: 94.76.225.145
Probable Submitter: 82.4.251.69
----
Manual Page -- http://www.php.net/manual/en/function.gzread.php
Edit -- https://master.php.net/note/edit/110078
Del: integrated -- https://master.php.net/note/delete/110078/integrated
Del: useless -- https://master.php.net/note/delete/110078/useless
Del: bad code -- https://master.php.net/note/delete/110078/bad+code
Del: spam -- https://master.php.net/note/delete/110078/spam
Del: non-english -- https://master.php.net/note/delete/110078/non-english
Del: in docs -- https://master.php.net/note/delete/110078/in+docs
Del: other reasons-- https://master.php.net/note/delete/110078
Reject -- https://master.php.net/note/reject/110078
Search -- https://master.php.net/manage/user-notes.php