Converting the text files into gzip file.


 

Converting the text files into gzip file.

This example will explain you how to convert text files into gzip file?.

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

?>

Ads