forked from ZemezLab/kava
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzip.php
33 lines (27 loc) · 853 Bytes
/
zip.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
$rootPath = realpath('.');
$zip = new ZipArchive();
$zip->open('tourware.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);
$zip->addEmptyDir('tourware');
/** @var SplFileInfo[] $files */
$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);
if (
substr($relativePath, 0, 6) !== '.github' &&
substr($relativePath, 0, 4) !== '.git' &&
substr($relativePath, 0, 5) !== '.idea' &&
substr($relativePath, 0, 7) !== 'zip.php'
) {
$zip->addFile($filePath, 'tourware/' . $relativePath);
}
}
}
$zip->close();