ConFoo Montreal 2026: Call for Papers

Voting

: one minus zero?
(Example: nine)

The Note You're Voting On

Anonymous
16 years ago
Here's a simple recurring function to add a directory, all sub-directories and all files to an already created zip file;

<?php
// Function to recursively add a directory,
// sub-directories and files to a zip archive
function addFolderToZip($dir, $zipArchive){
if (
is_dir($dir)) {
if (
$dh = opendir($dir)) {

//Add the directory
$zipArchive->addEmptyDir($dir);

// Loop through all the files
while (($file = readdir($dh)) !== false) {

//If it's a folder, run the function again!
if(!is_file($dir . $file)){
// Skip parent and root directories
if( ($file !== ".") && ($file !== "..")){
addFolderToZip($dir . $file . "/", $zipArchive);
}

}else{
// Add the files
$zipArchive->addFile($dir . $file);

}
}
}
}
}
?>

Would be nice to see more input on these functions :)

Dayjo

<< Back to user notes page

To Top