suche nach in der

gzrewind> <gzputs
Last updated: Sat, 07 Jan 2012

view this page in

gzread

(PHP 4, PHP 5)

gzreadLiest binary-safe aus einer gz-Datei

Beschreibung

string gzread ( resource $zp , int $length )

gzread() liest bis zu length Bytes aus der gegebenen gz-Datei Resource. Lesen stoppt, wenn length (unkomprimierte) Bytes gelesen wurden oder EOF (Dateiende) erreicht wurde, je anchdem, was zuerst eintrifft.

Parameter-Liste

zp

Die gz-Datei Resource. Dies muss auf eine gültige, erfolgreich mit gzopen() geöffnete Datei zeigen.

length

Die Anzahl der zu lesenden Bytes.

Rückgabewerte

Die gelesenen Daten.

Beispiele

Beispiel #1 gzread() Beispiel

<?php
// Liest den Inhalt einer gz-Datei in einen String
$filename "/usr/local/something.txt.gz";
$zd gzopen($filename"r");
$contents gzread($zd10000);
gzclose($zd);
?>

Siehe auch

  • gzwrite() - Ausgabe in gz-komprimierte Dateien
  • gzopen() - Öffnet gz-Dateien
  • gzgets() - Get line from file pointer
  • gzgetss() - Get line from gz-file pointer and strip HTML tags
  • gzfile() - Read entire gz-file into an array
  • gzpassthru() - Gibt alle verbleibenden Daten eines gz-Daei Deskriptors aus



add a note add a note User Contributed Notes
gzread
zaotong at yahoo dot com
08-Mar-2007 12:06
As was shown to me in another forum there is a way to get the uncompressed size of the gz file by viewing the last 4 bytes of the gz file.

Here is a piece of code that will do this
<?php
$FileRead
= 'SomeText.txt';
$FileOpen = fopen($FileRead, "rb");
       
fseek($FileOpen, -4, SEEK_END);
       
$buf = fread($FileOpen, 4);
       
$GZFileSize = end(unpack("V", $buf));
       
fclose($FileOpen);
       
$HandleRead = gzopen($FileRead, "rb");
       
$ContentRead = gzread($HandleRead, $GZFileSize);
?>

This will read the last 4 bytes of the gz file and use it as the file int for the gzread.

Thanks to stereofrog for helping me with this code.
methatron at hotmail dot com
27-Sep-2006 09:33
Be aware that gzread's second parameter - length reffers to the file's uncompressed size, therefore using this code:

<?php
$file_name
= "/usr/local/something.txt.gz";
if(
$file_handle = gzopen($file_name, "r"))
{
   
$contents = gzread($file_handle, filesize($file_name));
   
gzclose($file_name);
}
?>

will probably truncate the content of the file as filesize checks for the file's compressed size.
So either use the actual uncompressed size, if you know it, or use an aribtrary big enough length, as gzreading will stop at the end of the file anyway.

gzrewind> <gzputs
Last updated: Sat, 07 Jan 2012