diff --git a/core/module/config/config.php b/core/module/config/config.php index 09fc87b6..c5803bd0 100755 --- a/core/module/config/config.php +++ b/core/module/config/config.php @@ -199,18 +199,33 @@ class config extends common { * Sauvegarde des données */ public function backup() { - // Creation du ZIP - $fileName = date('Y-m-d-h-i-s', time()) . '.zip'; + $fileName = str_replace('/','',helper::baseUrl(false,false)) . '-'. date('Y-m-d-h-i-s', time()) . '.zip'; $zip = new ZipArchive(); - if($zip->open(self::TEMP_DIR . $fileName, ZipArchive::CREATE) === TRUE){ - foreach(configHelper::scanDir('site/') as $file) { - $zip->addFile($file); - } + $zip->open(self::TEMP_DIR . $fileName, ZipArchive::CREATE | ZipArchive::OVERWRITE); + $directory = 'site/'; + $filter = array('backup','tmp'); + $files = new RecursiveIteratorIterator( + new RecursiveCallbackFilterIterator( + new RecursiveDirectoryIterator( + $directory, + RecursiveDirectoryIterator::SKIP_DOTS + ), + function ($fileInfo, $key, $iterator) use ($filter) { + return $fileInfo->isFile() || !in_array($fileInfo->getBaseName(), $filter); + } + ) + ); + foreach ($files as $name => $file) { + if (!$file->isDir()) { + $filePath = $file->getRealPath(); + $relativePath = substr($filePath, strlen(realpath($directory)) + 1); + $zip->addFile($filePath, $relativePath); + } } $zip->close(); // Téléchargement du ZIP - header('Content-Transfer-Encoding: binary'); + header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename="' . $fileName . '"'); header('Content-Length: ' . filesize(self::TEMP_DIR . $fileName)); readfile(self::TEMP_DIR . $fileName);