Created
December 17, 2021 14:59
-
-
Save ahmeti/74ea417b8181c59a8534af6275d85026 to your computer and use it in GitHub Desktop.
Wordpress Backup With Client Request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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