function mkzip($znm, $src = array()){
$dnm = dirname(getcwd());
$zfd = new ZipArchive();
$zfd->open($znm, ZipArchive::CREATE | ZipArchive::OVERWRITE);
foreach ($src as $f1){
if(is_dir($f1))
addzipD($zfd, $dnm, ($f1));
else
addzipF($zfd, $dnm, ($f1));
}
$zfd->close();
}
function addzipF(&$zfd,&$dnm, &$f1){
$realfnm = realpath($f1);
$relativePath = substr($realfnm, strlen($dnm) + 1);
$zfd->addFile($realfnm, $relativePath);
}
function addzipD(&$zfd,&$dnm, &$f1){
if(!is_dir($f1)) return;
$files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($f1), RecursiveIteratorIterator::LEAVES_ONLY );
foreach ($files as $name => $f1)
{
if ($f1->isDir()) continue; // Skip directories (they would be added automatically)
addzipF($zfd, $dnm,$f1);
}
}
Sort: Trending