我在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,然后压缩整个目录,但是如何才能不将updatenew.zip添加到压缩文件中呢?
发布于 2015-08-01 03:31:12
从更新您的条件
if (!$file->isDir())添加到类似于
if (!$file->isDir() AND (strpos($name, 'updatenew.zip') === FALSE))这将跳过文件名中包含'updatenew.zip‘的所有文件。
https://stackoverflow.com/questions/30697259
复制相似问题