Php 下载的Ziparcheves无法读取

Php 下载的Ziparcheves无法读取,php,download,ziparchive,Php,Download,Ziparchive,我正在尝试下载文件夹my_文件夹中的文件。在文件上创建zip文件并使用php下载。这是我试过的 <?php $path = '/my_folder/path/'; $handle=opendir($path); $files = array(); while(false!==($file = readdir($handle))) { $files[] = $path . $file; } $zipname = 'file.zip'; $zip = new ZipArchiv

我正在尝试下载文件夹my_文件夹中的文件。在文件上创建zip文件并使用php下载。这是我试过的

<?php

$path = '/my_folder/path/';
$handle=opendir($path); 
$files = array();
while(false!==($file = readdir($handle)))
 {
    $files[] = $path . $file;
 }
$zipname = 'file.zip';
$zip = new ZipArchive;
if($zip->open($zipname, ZipArchive::CREATE) == TRUE){
    foreach ($files as $file) {
      $zip->addFile($file);
    }
    $zip->close();
}

header('Content-Type: application/zip');
header('Content-disposition: attachment; filename=filename.zip');
header('Content-Length: ' . filesize($zipname));
header("Pragma: no-cache"); 
header("Expires: 0");
readfile($zipname);
unlink($zipname);
?>
看起来它工作得很好。它下载zip文件,但当我试图提取zip时,它给出了带有错误消息Archieve的密码对话框,无法读取;您想试试密码吗 有谁能告诉我代码中有什么错误,或者如何避免这种对话并提取文件