I have a code that compresses file and directory. The problem is that it compresses the files and directories that are in the root, but the subdirectories they are not compressed, for example I have these directories:
folder /, folder / file.php, folder / other / folder2, file1.php
It only compresses / folder and file1.php ...
It should compress the .php file, another /, folder2 /
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);
?>