Share on Google+Share on Google+

Converting the text files into gzip file.

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);

?>

Advertisements

Advertisement

Posted on: July 30, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial 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.