Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $zipname = 'bk.zip';
- function folderToZip($folder, &$zipFile, $exclusiveLength)
- {
- set_time_limit(0);
- $handle = opendir($folder);
- while (false !== $f = readdir($handle))
- {
- if ($f != '.' && $f != '..')
- {
- $filePath = "$folder/$f";
- $localPath = substr($filePath, $exclusiveLength);
- if (is_file($filePath))
- {
- $zipFile->addFile($filePath, $localPath);
- }
- elseif (is_dir($filePath))
- {
- $zipFile->addEmptyDir($localPath);
- folderToZip($filePath, $zipFile, $exclusiveLength);
- }
- }
- }
- closedir($handle);
- }
- function zipDir($sourcePath, $outZipPath)
- {
- $pathInfo = pathInfo($sourcePath);
- $parentPath = $pathInfo['dirname'];
- $dirName = $pathInfo['basename'];
- $z = new ZipArchive();
- $z->open($outZipPath, ZIPARCHIVE::CREATE);
- $z->addEmptyDir($dirName);
- folderToZip($sourcePath, $z, strlen("$parentPath/"));
- $z->close();
- }
- zipDir('.', $zipname);
- header('Content-Type: application/zip');
- header("Content-Disposition: attachment; filename='bk.zip'");
- header('Content-Length: ' . filesize($zipname));
- header("Location: bk.zip");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement