在PHP中将文件添加到现有Zip [关闭]

How to add files to existing zip via PHP? I have a zip file test.zip contains five files, now I want to add 20 more files to that zip. So my updated zip will contain 25 files.

array_push('sortname','fullpath');                      
$zip = new ZipArchive();
if ($zip->open('/path_to_folder/fileName'.'.zip',ZIPARCHIVE::CREATE) !== TRUE) {
    die ("Could not open archive");
}
foreach ($fileList as $key=>$value) {
    $zip->addFile($key,$value) or die ("ERROR: Could not add file: $f");
}
$zip->close();

it will create new zip if it does not exist,otherwise add files to the same zip file

i created one zip file called index.php in my public folder with index.php file compressed in it.than i written following code to programatically add 2 new files to it and its perfectly working for me

$zip = new ZipArchive();
$filename = APPLICATION_PATH."\..\public\index.zip";

if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
    exit("cannot open <$filename>
");
}
try{
    $zip->addFile(APPLICATION_PATH."\..\public\index4.php","index4.php") or die ("ERROR: Could not add file:");
     $zip->addFile(APPLICATION_PATH."\..\public\web.config","web.config") or die ("ERROR: Could not add file:");

}
catch (Exception $e){
    echo  $e->getMessage();exit;
}
echo "numfiles: " . $zip->numFiles . "
";
echo "status:" . $zip->status . "
";
$zip->close();