teste
and it has several files and subfolders (with more subfolders inside) , and would like to pack all of this with php.
So far I only have this code, but it compacts the entire path and not just where I indicated it, for example, if I indicate to it to compact teste/teste1/
it will not compress what is inside teste1
and yes the path integer from teste
.
$directory = DIR_ARQUIVOS.'yNPA8Bg0GFLV';
$zipfile = DIR_ARQUIVOS.'yNPA8Bg0GFLV.zip';
$filenames = array();
function browse($dir)
{
global $filenames;
if ($handle = opendir($dir))
{
while (false !== ($file = readdir($handle)))
{
if($file != "." && $file != ".." && is_file($dir.'/'.$file) && $dir != './arquivos/yNPA8Bg0GFLV')
{
echo $dir. "<br/>";
$filenames[] = $dir.'/'.$file;
}
else if ($file != "." && $file != ".." && is_dir($dir.'/'.$file))
{
browse($dir.'/'.$file);
}
}
closedir($handle);
}
return $filenames;
}
browse($directory);
$zip = new ZipArchive();
if ($zip->open($zipfile, ZIPARCHIVE::CREATE)!== TRUE){exit("cannot open <$zipfile>\n");}
foreach ($filenames as $filename)
{
echo "Adding " . $filename . "<br/>";
$zip->addFile($filename,$filename);
}
$zip->close();