Skip to content

Instantly share code, notes, and snippets.

@ahmeti
Created December 17, 2021 14:59
Show Gist options
  • Save ahmeti/74ea417b8181c59a8534af6275d85026 to your computer and use it in GitHub Desktop.
Save ahmeti/74ea417b8181c59a8534af6275d85026 to your computer and use it in GitHub Desktop.
Wordpress Backup With Client Request
<?php
ini_set('max_execution_time', 0);
error_reporting(E_ALL);
ini_set('display_errors','On');
$rootPath = realpath(__DIR__);
$zip = new ZipArchive();
$zip->open('backup_'.uniqid().'.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($rootPath),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $name => $file)
{
if( ! in_array($file->getFilename(), ['.', '..']) ){
// Skip directories (they would be added automatically)
if ( ! $file->isDir() )
{
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($rootPath) + 1);
$zip->addFile($filePath, $relativePath);
}
}
}
$zip->close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment