This question already has an answer here:
I need to allow my user to backup his public_html folder, but I want to zip everything except my own "rules folder". I've found a very nice answer here (working pretty good, but the exported zip file contains my rules folder aswell). So the question is how to detect the folder and just ignore it?
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($rootPath),
RecursiveIteratorIterator::LEAVES_ONLY
);
$exclude = array("rulles_folder");
foreach ($files as $name => $file) {
var_dump($file -> getFilename());
if ($file -> isDir() && !in_array($file -> getFilename(), $exclude)) {
salta();
} else {
// Skip directories (they would be added automatically)
if (!$file -> isDir()) {
// Get real and relative path for current file
$filePath = $file -> getRealPath();
$relativePath = substr($filePath, strlen($rootPath) + 0);
// Add current file to archive
$zip -> addFile($filePath, $relativePath);
}
}
}
function salta () {
;
}
var_dump returns
string(1) "." string(2) ".." string(9) ".DS_Store" string(9) "index.php"
and so on, no Folder names at all, so when I call
if ($file -> isDir() && !in_array($file -> getFilename(), $a_excluir))
nothing happens because no folder names exists
Any suggestion please?
Thanks
</div>