themeName = $themeName; if (!$this->setThemeDirectory($themeDirectory)) { $this->setErrorMessage('Theme directory does not exists'); } if (!$this->setTempDirectory($tempDirectory)) { $this->setErrorMessage('Temp directory is not writable or does not exists'); } if (!$this->createZip()) { $this->setErrorMessage('The ZIP file could not be created'); @unlink($this->tempFile); } } function createZip() { $this->tempFile = $this->tempDirectory . '/' . md5(rand()) . '.zip'; $archive = new PclZip($this->tempFile); //preg_match('~^(.*)/.*$~', $this->themeDirectory, $matches); //$removeDirectory = $matches[1] . '/'; $v_list = $archive->create($this->themeDirectory, PCLZIP_OPT_REMOVE_PATH, $this->themeDirectory, PCLZIP_OPT_ADD_PATH, $this->themeName); if ($v_list == 0) { return false; } return true; } function sendZip() { $contents = file_get_contents($this->tempFile); unlink($this->tempFile); header("Content-type: application/zip"); header('Content-Disposition: attachment; filename="' . $this->themeName . '.zip"'); echo $contents; die(); } function setErrorMessage($message) { $this->errorMessage = $message; } function getLastError() { return $this->errorMessage; } function setThemeDirectory($directory) { if (is_readable($directory)) { $this->themeDirectory = $directory; return true; } else { return false; } } function setTempDirectory($directory) { if (is_writable($directory)) { $this->tempDirectory = $directory; return true; } else { return false; } } } ?>