Created
February 20, 2011 13:39
-
-
Save MasterEx/835970 to your computer and use it in GitHub Desktop.
PHP zip file creation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* ---------------------------------------------------------------------------- | |
* "THE BEER-WARE LICENSE" (Revision 42): | |
* <[email protected]> wrote this file. As long as you retain this notice you | |
* can do whatever you want with this stuff. If we meet some day, and you think | |
* this stuff is worth it, you can buy me a beer in return Periklis Ntanasis | |
* ---------------------------------------------------------------------------- | |
*/ | |
function zipFiles($destination,$files=array(),$file_names=array(),$overwrite=true) { | |
if(file_exists($destination) && !$overwrite) | |
return false; | |
$zip = new ZipArchive(); | |
$res = $zip->open($destination,$overwrite ? ZipArchive::OVERWRITE : ZipArchive::CREATE); | |
if(!$res) | |
return false; | |
if(count($file_names)>0) | |
$with_names=true; | |
else | |
$with_names=false; | |
for($i=0;$i<count($files);$i++) | |
{ | |
if($with_names) | |
$zip->addFile($files[$i],$file_names[$i]); | |
else | |
$zip->addFile($files[$i]); | |
} | |
$zip->close(); | |
return file_exists($destination); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment