Thursday, March 8, 2012

How to create a compressed zip file using php?


<?
// Create Compressed File.
function createZip()
     {
    $file_to_compress = "sample.txt"; //put any type of file
    $file_to_produce="sample.txt.zip";
   $data = implode("", file($file_to_compress));
   $zipdata = gzencode($data, 9);
   $filep = fopen($file_to_produce, "w");
   fwrite($filep, $zipdata);
     }
echo createZip(); // call the function.it will create a zip file which has place this file location.
 ?>

No comments:

Post a Comment