Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Add files and sub-directories in a folder to zip file.
- * @param string $folder
- * @param ZipArchive $zipFile
- * @param int $exclusiveLength Number of text to be exclusived from the file path.
- */
- private function folderToZip($folder, &$zipFile, $exclusiveLength) {
- $handle = opendir($folder);
- while (false !== $f = readdir($handle)) {
- if ($f != '.' && $f != '..') {
- $filePath = "$folder/$f";
- // Remove prefix from file path before add to zip.
- $localPath = substr($filePath, $exclusiveLength);
- if (is_file($filePath)) {
- $zipFile->addFile($filePath, $localPath);
- } elseif (is_dir($filePath)) {
- // Add sub-directory.
- $zipFile->addEmptyDir($localPath);
- $this->folderToZip($filePath, $zipFile, $exclusiveLength);
- }
- }
- }
- closedir($handle);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement