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