-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompressor.php
58 lines (52 loc) · 1.34 KB
/
Compressor.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
<?php
class Compressor{
private $zip;
private $overwrite;
private $newApxl;
private $folder;
public function __construct($sourceFolder, $overwrite = true){
$this->zip= new ZipArchive();
$this->overwrite = $overwrite;
$this->folder = $sourceFolder;
}
public function makeKey($name){
if($this->zip->open($name, $this->overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
Utils::log('Cannot open destination file');
die();
}
$this->rec_zip($this->folder);
}
public function addNewIndex($newIndex){
if (file_exists($newIndex)){
$this->zip->addFile($newIndex, 'index.apxl');
} else {
Utils::log('New index not found');
die();
}
}
public function closeKey(){
$this->zip->close();
echo "File Created\n";
}
private function rec_zip($folder){
$dir = new DirectoryIterator($folder);
foreach ($dir as $element) {
if (!$element->isDot()) {
if ($element->isDir()) {
$newdir = $element->getFilename();
$newfolder = "$folder/$newdir";
$this->rec_zip($newfolder);
} else {
$path = $element->getPath();
$name = $element->getFilename();
$fullpath = "$path/$name";
$exp = explode('/', $fullpath);
array_shift($exp);
$fullname = implode('/', $exp);
//echo "$fullpath - $fullname\n";
$this->zip->addFile($fullpath, $fullname);
}
}
}
}
}