0
我在PHP中使用創建zip文件,但我想排除zip文件本身。PHP創建zip但排除zip文件
$rootPath = realpath('../../');
$zip = new ZipArchive();
$zip->open('../../includes/updatenew.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($rootPath),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $name => $file)
{
if (!$file->isDir())
{
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($rootPath) + 1);
$zip->addFile($filePath, $relativePath);
}
}
$zip->close();
此代碼首先創建了../../includes/updatenew.zip然後拉鍊整個目錄,但我怎麼能排除在zip添加的updatenew.zip?