Home Tutorial Php Examples Converting the text files into gzip file.

 
 

Converting the text files into gzip file.
Posted on: July 30, 2009 at 12:00 AM
Advertisement
This example will explain you how to convert text files into gzip file?.

Converting text file into gzip file

This example will explain you how to convert text files into gzip file. Under gzip operation, first text files will be compressed and then it will be converted into .gz file. See the examples in steps:

Begin the PHP tag, 

Define the file to be compressed.

Define the gzip file to be produce.

Use implode() function to  compress the file.

Generate gzipcode  from gz temporary file.

open the file, Write in gzip file from gzdata, close the gzfile

Now, read the converted gzfile producer 

end the phph tag.

<?php
# Compress text file into gzip and write gzip and read gzip file operation

$filecompress = "File.txt"; //any type of file
$gzfileproduce="New.txt.gz";
$data= implode("", file($filecompress));
$gzdata = gzencode($data, 9);
$fopen = fopen($gzfileproduce, "w");
fwrite($fopen, $gzdata);
fclose($fopen);
$fopen = fopen($gzfileproduce, "r");
echo fread($fopen, 10);
fclose($fopen);

?>

Advertisement

Related Tags for Converting the text files into gzip file.:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 30, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com