Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

Compressed File Functions


The functions in this section use the zlib library to work with files compressed with GNU
compression tools, such as gzip. The library was written by Jean-loup Gaill and Mark
Adler. The two are authors of the gzip tool, in fact. You can obtain more information and
the library itself from the zlib home page http://www.cdrom.com/pub/infozip/zlib/.


In order to activate these functions, you must include the zlib extension. On a UNIX
operating system, you configure PHP to use zlib as you compile it. On Windows you may
activate the php_zlib.dll extension either in php.ini or using the dl function.


Most of the functions for reading and writing files are duplicated here and they operate
similarly. One difference is the lack of support for specifying files using HTTP or FTP
protocol.


boolean gzclose(integer file_handle)


The gzclose function closes a file opened with gzopen. TRUE is returned if the file closed
successfully. FALSE is returned if the file cannot be closed. See gzgets for an example of
use.


boolean gzeof(integer file_handle)


As you read from a compressed file, PHP keeps a pointer to the last place in the file you
read. The gzeof function returns TRUE if you are at the end of the file. See gzgets for an
example of use.


array gzfile(string filename, boolean use_include_path)


The gzfile function reads an entire file into an array. The file is first uncompressed.
Each line of the file is a separate element of the array, starting at zero. The optional
use_include_path argument causes gzfile to search for the file within the include path
specified in php.ini.


<?
// open file and print each line
$myFile = gzfile( "data.gz");
for($index = 0; $index < count($myFile); $index++)
{
print($myFile[$index]);
}
?>


string gzgetc(integer file_handle)

Free download pdf