-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackager.php
More file actions
60 lines (53 loc) · 2.03 KB
/
packager.php
File metadata and controls
60 lines (53 loc) · 2.03 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
require('assets/functions.php');
echo '欲打包版本:'.$localVersion.'<br>';
// 打包安装包
$excludeFiles = array('packager.php','RisProjectManager_Full.zip','RisProjectManager_Update.zip','download.php');
$excludeDirs = array('.well-known');
packager($excludeFiles,$excludeDirs,'RisProjectManager_Full.zip');
// 打包升级包
$excludeFiles = array('packager.php','RisProjectManager_Full.zip','RisProjectManager_Update.zip','config.php','favicon.ico','download.php','projects.json');
$excludeDirs = array('.well-known');
packager($excludeFiles,$excludeDirs,'RisProjectManager_Update.zip');
function packager($excludeFiles,$excludeDirs,$zipFileName) {
// 创建一个新的zip实例
$zip = new ZipArchive();
// 打开或创建zip文件
if ($zip->open($zipFileName, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== TRUE) {
die ("无法创建或打开文件");
}
// 获取当前目录的绝对路径
$currentDir = realpath('.');
// 遍历当前目录下的所有文件
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($currentDir, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST
);
foreach ($files as $file) {
// 获取文件的绝对路径
$filePath = $file->getRealPath();
// 检查文件是否在排除列表中
if (!in_array($file->getFilename(), $excludeFiles)) {
// 检查文件所在目录是否在排除列表中
$excludeDir = false;
foreach ($excludeDirs as $dir) {
if (strpos($filePath, $currentDir . DIRECTORY_SEPARATOR . $dir) === 0) {
$excludeDir = true;
break;
}
}
if (!$excludeDir) {
// 计算文件的相对路径,确保不包含父目录
$relativePath = substr($filePath, strlen($currentDir) + 1);
// 如果是文件则添加到zip中
if ($file->isFile()) {
$zip->addFile($filePath, $relativePath);
}
}
}
}
// 关闭zip
$zip->close();
echo "打包".$zipFileName."完成!<br>";
}
?>