note 38967 added to function.gzfile
| From: | webmaster at ragnarokonline dot de | Date: | Tue, 13 Jan 2004 16:58:30 +0000 |
| Subject: | note 38967 added to function.gzfile | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-63465@lists.php.net to get a copy of this message | ||
This is a port of what I've posted at http://www.php.net/file_get_contents
It works similar to gzfile() but it returns the file in a string instead of an array and
doesn't write it to stdout compared to readgzfile.
Note: unlike the usual file-functions filesize won't work here, since the length-parameter of
gzread refers to the uncompressed length, while filesize returns the size of the compressed file.
<?php
if (!function_exists('gzfile_get_contents')) {
function gzfile_get_contents($filename, $use_include_path = 0) {
$file = @gzopen($filename, 'rb', $use_include_path);
if ($file) {
$data = ''; // just to be safe. Dunno, if this is really needed
while (!gzeof($file)) $data .= gzread($file, 1024);
gzclose($file);
}
return $data;
}
}
?>
PS: if (!function_exists('gzfile_get_contents')) {
[...]
}
isn't really needed, but just in case.
----
Manual Page -- http://www.php.net/manual/en/function.gzfile.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+38967
Delete -- http://master.php.net/manage/user-notes.php?action=delete+38967&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+38967&report=yes
Search -- http://master.php.net/manage/user-notes.php