['backup', 'tmp', 'file'], 'data' => ['backup', 'tmp', 'data'], 'i18n' => ['backup', 'tmp', 'i18n'], ]; // Vérification et traitement du paramètre "filter" en GET if (isset($_GET['filter']) && isset($filterDirectories[$_GET['filter']])) { $filter = $filterDirectories[$_GET['filter']]; } // Création du ZIP $fileName = date('Y-m-d-H-i-s', time()) . '-rolling-backup.zip'; $zip = new ZipArchive(); $zip->open('../../../../site/backup/' . $fileName, ZipArchive::CREATE | ZipArchive::OVERWRITE); $directory = '../../../../site'; $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(); http_response_code(201); // Création de l'archive réussie, renvoie une réponse avec le code 201 Created } ?>