1: | <?php |
2: | |
3: | namespace ngatngay; |
4: | |
5: | class zip extends \ZipArchive { |
6: | public function add($path, $relative = null) |
7: | { |
8: | if (!file_exists($path)) { |
9: | return false; |
10: | } |
11: | |
12: | $file = new \SplFileInfo($path); |
13: | $path = $file->getPathname(); |
14: | $pathRelative = $path; |
15: | |
16: | if ($relative) { |
17: | $pathRelative = substr($path, strlen($relative)); |
18: | } |
19: | |
20: | if ($file->isFile()) { |
21: | $this->addFile($path, $pathRelative); |
22: | } |
23: | |
24: | if ($file->isDir()) { |
25: | $this->addEmptyDir($pathRelative); |
26: | } |
27: | } |
28: | } |
29: | |