create zip file using php
by Guna[ Edit ] 2012-07-23 18:47:23
Zip file is a compressed file which can mainly stored as .zip extension and its well known compression format to gather datas and
its very simple with PHP with Zip Archive class. Following function create a zip file called sample.zip with sample.php in it.
function create_zip($source, $destination,$overwrite='')
{
$zip = new ZipArchive();
if($zip->open($destination,$overwrite?ZIPARCHIVE::OVERWRITE:ZIPARCHIVE::CREATE)===TRUE)
{
$zip->addFile($source);// Add the files to the .zip file
$zip->close(); // Closing the zip file
}
}
create_zip("sample.php","sample.zip");