如何在一个文件夹中添加所有选定的文件,并使其在php中压缩

I have made one folder and add all the file into this folder and when I unzip folder it is showing some error..here is the errorenter image description here

here is my code..

 $files=$_POST['check_list']; 
 $zipname = 'kmm.zip';
 $zip = new ZipArchive;
 $zip->open('kmm.zip', ZipArchive::CREATE |ZipArchive::OVERWRITE);

 foreach ($files as $file) 
 { 
     $file="audio/$file";
     $zip->addFile($file);
     $zip->close();
 } 

 header('Content-Type: application/zip');
 header("Content-Disposition: attachment; filename=kmm.zip");
 header('Content-Length: ' . filesize($zipname));

First of all add some more details. Make sure your files are not corrupted or broken. Few years ago i spend hours trying to get the zip method working. So double check it!
Try using this.

    $zip = new ZipArchive();
foreach ($files as $file) {



    $filename = 'yourzip.zip';
    $thisdir = 'audio/'; //This is directory

    //check if file can be openend
    if ($zip->open($filename, ZipArchive::CREATE)!==TRUE) {
        exit("cannot open <$filename>
");
    }
    //This is where the magic happens
    $zip->addFromString($file .'-'. time(), "Whatever you like to do with your files");
    $zip->addFile($thisdir . $file");

}
    echo "numfiles: " . $zip->numFiles . "
";
    echo "status:" . $zip->status . "
";**strong text**
    $zip->close();
    ?>

Before closing the zip make sure it completed the foreach. to test it

echo "<pre>",print_r($zip->status),"</pre>";