5
I have this function that makes the .zip of the current folder to save. But I want you to save to the folder backup.
$data = date("d_m_y");
$exten = "_backup.zip"; // Nome final com extensão
class Zipper extends ZipArchive
{
public function Compact($cwd) {
$open = opendir($cwd);
while($folder = readdir($open))
{
if ($folder != '.' && $folder != '..')
{
if (is_dir($cwd.'/'.$folder))
{
$dir = str_replace('./', '',($cwd.'/'.$folder));
$this->addEmptyDir($dir);
$this->Compact($dir);
}
elseif (is_file($cwd.'/'.$folder))
{
$arq = str_replace('./', '',$cwd.'/'.$folder);
$this->addFile($arq);
}
}
}
}
}
$zip = new Zipper();
if ($zip->open($data.$exten, ZIPARCHIVE::CREATE) === true){
$zip->Compact(".");
}
$zip->close();`
It worked, but it was necessary to leave the directory path without the first bar: $directory = "backup/"
– Expl0it
I corrected the answer, put the function
getcwd();which takes the directory you are currently in and puts the folderbackup. Whenever an answer is correct, mark it as correct so that others with the same doubt know that the proposed solution worked. Another thing, to get it right use./backup/arquivo.zipuse the.at first.– Antony Alkmim