当只有一个文件要添加到Zip文件时,我的代码工作得非常好但是只要我将多个文件添加到zip中,我就会得到以下文件:Photos.zip.gefBCk!
以下是我创建ZipArchive的代码:
$zip = new ZipArchive;
if ($zip->open('/var/www/html/downloads/' . $user . '/photos.zip', ZipArchive::CREATE))
{
if($handle = opendir('/var/www/html/downloads/' . $user . '/'))
{
while (false !== ($entry = readdir($handle)))
{
if ($entry != "." && $entry != ".." && !is_dir('/var/www/html/downloads/' . $user . '/' . $entry))
{
if(strpos($entry, '.png') !== false)
{
$zip->addFile('/var/www/html/downloads/' . $user . '/' . $entry, basename('/var/www/html/downloads/' . $user . '/' . $entry));
}
}
}
closedir($handle);
}
$zip->close();
感谢您的时间!