ConFoo Montreal 2026: Call for Papers

Voting

: min(zero, eight)?
(Example: nine)

The Note You're Voting On

Dean Rather
12 years ago
This add directory function does not require that you create a new wrapper class, and also does not add the entire file directory tree into your zip file.

<?php

public function addDirectoryToZip($zip, $dir, $base)
{
$newFolder = str_replace($base, '', $dir);
$zip->addEmptyDir($newFolder);
foreach(
glob($dir . '/*') as $file)
{
if(
is_dir($file))
{
$zip = $this->addDirectoryToZip($zip, $file, $base);
}
else
{
$newFile = str_replace($base, '', $file);
$zip->addFile($file, $newFile);
}
}
return
$zip;
}

?>

<< Back to user notes page

To Top