8
I have a code that compacts file and directory. The problem is that it compresses the files and directories that are at the root, but the subdirectories they are not compressed, for example I have these directories:
folder/, folder/file.php, folder/other/paste2, archive1.php
it only compact folder/ and archive1.php ...
It should compress the php file, other/, pasture2/
Code:
<?php
function Show_files($local){
$zip = new ZipArchive();
if($zip->open('compact.zip', ZIPARCHIVE::CREATE) == TRUE){
$open = opendir($local);
while($folder = readdir($open)){
if(is_dir($local.$folder) && $folder != '.' && $folder != '..'){
echo $local.$folder.'<br>';
$zip->addEmptyDir($folder);
Show_files($local.$folder.'/');
}elseif(is_file($local.$folder) && $folder != '.' && $folder != '..'){
$zip->addFile($local.$folder, $folder);
echo $local.$folder.'<br>';
}
}
}
}
$raiz = str_replace("\\", "/", getcwd())."/";
Show_files($raiz);
?>