In PHP4.4.1 I noticed that gzfile only reads up to 8190 bytes per line. I had a 20K SQL query that was cut into 3 parts - and wondered why the SQL server complained.
Reading an uncompressed file with the file() command works as expected.
gzfile
(PHP 4, PHP 5)
gzfile — Lee un archivo gz completo en una matriz
Descripción
array gzfile
( string $nombre_archivo
[, int $usar_ruta_inclusion
] )
Función idéntica a readgzfile(), excepto que gzfile() devuelve el archivo en una matriz.
Lista de parámetros
- nombre_archivo
-
El nombre del archivo.
- usar_ruta_inclusion
-
Puedes asignar este parámetro opcional a 1, si deseas buscar también el archivo eninclude_path.
Valores retornados
Una matriz que contiene el archivo, una línea por celda.
Ejemplos
Example #1 Ejemplo de gzfile()
<?php
$lines = gzfile('somefile.gz');
foreach ($lines as $line) {
echo $line;
}
?>
gzfile
nb_nonospamm_ at wtal dot de
27-Nov-2005 01:12
27-Nov-2005 01:12
The Jedi
28-Jun-2005 03:44
28-Jun-2005 03:44
A quicker way to load a gziped file in a string :
<?php
function gzfile_get_contents($filename, $use_include_path = 0)
{
//File does not exist
if( !@file_exists($filename) )
{ return false; }
//Read and imploding the array to produce a one line string
$data = gzfile($filename, $use_include_path);
$data = implode($data);
return $data;
}
?>
webmaster at ragnarokonline dot de
13-Jan-2004 08:58
13-Jan-2004 08:58
This 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
function gzfile_get_contents($filename, $use_include_path = 0) {
$file = @gzopen($filename, 'rb', $use_include_path);
if ($file) {
$data = '';
while (!gzeof($file)) {
$data .= gzread($file, 1024);
}
gzclose($file);
}
return $data;
}
?>
