0
How to compress a file say xxx.xml of 6MB into xxx.xml.gz using php program. 

How do you create a .gz file using PHP?

This solution doesn't work for me. it produce one .gz file which cant be open. it should be not just .gz it should be xxx.xml.gz

 $source='xxx.xml'; function gzCompressFile($source, $level = 9){ $dest = $source . '.gz'; $mode = 'wb' . $level; $error = false; if ($fp_out = gzopen($dest, $mode)) { if ($fp_in = fopen($source,'rb')) { while (!feof($fp_in)) gzwrite($fp_out, fread($fp_in, 1024 * 512)); fclose($fp_in); } else { $error = true; } gzclose($fp_out); } else { $error = true; } if ($error) return false; else return $dest; } /////////////////////////////////////////////////////////////compresion of output file ends here //call gzCompressFile function starts gzCompressFile(); // call gzCompressFile function ends 

The other solution below is only for string not for file.

 <?php $string = 'Some information to compress'; $gz = gzopen('somefile.gz','w9'); gzwrite($gz, $string); gzclose($gz); ?> 

Above one is for only string compression not for file compression Kindly help me to fix it.

6
  • 1
    It's not limited to 512KB. Reread your link. Commented Sep 1, 2016 at 9:44
  • I implemented the link instead of getting xxx.xml.gz as output file generated in server. i get jut un openable .gz file Commented Sep 1, 2016 at 9:59
  • 6MB isn't a large file. You shouldn't need to even bother with splitting the files. See the second answer on the link. Commented Sep 1, 2016 at 10:04
  • You dont pass the filename to gzCompressFile Commented Sep 1, 2016 at 10:29
  • php.net/variables.scope Commented Sep 1, 2016 at 10:30

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.