Function to compress and uncompress .gz file


SUBMITTED BY: Guest

DATE: March 29, 2015, 12:28 a.m.

FORMAT: PHP

SIZE: 528 Bytes

HITS: 2124

  1. <?php
  2. function uncompress($srcName, $dstName) {
  3. $string = implode("", gzfile($srcName));
  4. $fp = fopen($dstName, "w");
  5. fwrite($fp, $string, strlen($string));
  6. fclose($fp);
  7. }
  8. function compress($srcName, $dstName)
  9. {
  10. $fp = fopen($srcName, "r");
  11. $data = fread ($fp, filesize($srcName));
  12. fclose($fp);
  13. $zp = gzopen($dstName, "w9");
  14. gzwrite($zp, $data);
  15. gzclose($zp);
  16. }
  17. compress("test.php","test.gz");
  18. uncompress("test.gz","test2.php");
  19. ?>

comments powered by Disqus