Web студия "GrandView"
  Главная   Написать Контакты
   
   
О проекте
Руководство php
 

gzread

(PHP 3, PHP 4, PHP 5)

gzread -- Бинарное чтение gz-файла

Описание

string gzread ( resource zp, int length )

Читает (распаковывая) до length байт из gz-файла по указателю на него. Чтение заканчивается при достижении максимальной длины или конца файла (EOF).

Список параметров

zp

Указатель на gz-файл, возвращённый, после его успешного открытия, функцией gzopen().

length

Количество байт (после распаковки), которые следует считать.

Возвращаемые значения

Прочтённые данные.

Примеры

Пример 1. Пример использования gzread()

<?php
// поместить содержимое gz-файла в строку
$filename = "/usr/local/something.txt.gz";
$zd = gzopen($filename, "r");
$contents = gzread($zd, 10000);
gzclose($zd);
?>



add a note add a note User Contributed Notes
gzread
zaotong at yahoo dot com
07-Mar-2007 03: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 12: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, 27 Jan 2007
 
 
Новости
11 июля 2007
Сайт запущен
© 2007 info@grandviewstudio.com

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 324

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 330
Z058440144362 Z348613067571