I want to compress a .txt
file in PHP while maintaining the file extension. When I decompress the .gz
file the extension (.txt
) in the .gz
file is removed. (test.txt
becomes -> test
)
Here's a example of my PHP code to compress test.txt
into a .gz
file:
<?php
// Name of the file we are compressing
$file = "test.txt";
// Name of the gz file we are creating
$gzfile = "test.gz";
// Open the gz file (w9 is the highest compression)
$fp = gzopen ($gzfile, 'w9');
// Compress the file
gzwrite ($fp, file_get_contents($file));
// Close the gz file and we are done
gzclose($fp);
?>
Does someone knows what I'm doing wrong? Or is this because gzip
limations?