-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-zip.php
59 lines (50 loc) · 1.65 KB
/
create-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
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
<?php
include_once('header.inc.php');
$zipname = "zips/project".crc32(session_id()).".zip";
if(file_exists($zipname)) {
$response['status'] = "ok";
$response['file'] = $zipname;
} else {
$zip = new ZipArchive();
if($zip->open($zipname, ZipArchive::CREATE) === true) {
$dirGeneration = getDirGeneration();
if(isset($_POST['debug'])) {
if($_POST['debug'] == 1)
$dirGeneration = OUTPUT_DIR;
}
// Fichiers générés
foreach(getListDir(getDirGeneration().'/') as $file) {
$fileParts = explode(".", $file);
if($fileParts[count($fileParts)-1] == "html")
$zip->addFile($dirGeneration.'/'.$file, $file);
}
// Dependencies CSS
$dirCss = $dirGeneration.'/'.DEPENDENCIES_DIR.'/css/';
foreach(getListDir($dirCss) as $file) {
$fileParts = explode(".", $file);
if($fileParts[count($fileParts)-1] == "css")
$zip->addFile($dirCss.$file, DEPENDENCIES_DIR.'/css/'.$file);
}
$dirCssImg = $dirGeneration.'/'.DEPENDENCIES_DIR.'/css/images/';
foreach(getListDir($dirCssImg) as $file) {
$fileParts = explode(".", $file);
if($fileParts[count($fileParts)-1] == "png")
$zip->addFile($dirCssImg.$file, DEPENDENCIES_DIR.'/css/images/'.$file);
}
// Dependencies JS
$dirJs = $dirGeneration.'/'.DEPENDENCIES_DIR.'/js/';
foreach(getListDir($dirJs) as $file) {
$fileParts = explode(".", $file);
if($fileParts[count($fileParts)-1] == "js")
$zip->addFile($dirJs.$file, DEPENDENCIES_DIR.'/js/'.$file);
}
$zip->setArchiveComment("Powered by PetriMedia");
$zip->close();
$response['status'] = "ok";
$response['file'] = $zipname;
} else {
$response['status'] = "err";
}
}
echo json_encode($response);
?>