<?php
/**
* Summary Add all files in all folders and subfolders into a ZipArchive
*
* Description. Add all files in all folders and subfolders into a ZipArchive
*
* @filename ZipFolderTree.php
*
* @package None
* @subpackage None
* @since 1.0.0
* @author Mat Jung, https://www.phpclasses.org/browse/author/869460.html
* Usage
* Input: targetPfad: FileName, Name of Output Zip ( zip should not exist )
* Input: directory: FolderName, Name of folder to be zipped
*
* put ZipFolderTree.php into the parent folder
*/
$targetPfad="MediaWiki30.zip";
$directory = new RecursiveDirectoryIterator('MediaWiki30');
$recursiveIterator = new RecursiveIteratorIterator($directory);
if(file_exists($targetPfad)) { die("Zip Archive Found Exception");}
$zip = new ZipArchive();
$zipArchive = $targetPfad;
if ($zip->open($zipArchive, ZipArchive::CREATE)!==TRUE) {
exit("cannot open <$filename>\n");
}
foreach( $recursiveIterator as $info ){
if ($info->getFilename() == ".") continue; // ignore . and ..
if ($info->getFilename() == "..") continue;
echo $info->getPathname() . "<br>\n";
$zip->addFile($info->getPathname());
echo "Status and Files: " . $zip->status . " " . $zip->numFiles . "<br>\n";
}
$zip->close();
?>
|