forked from ZwiiCMS-Team/ZwiiCMS
Fonction backup avec exclusion tmp et backup
This commit is contained in:
parent
1b83c4bb5e
commit
5c4bdddb21
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user