From b46e2f324a69d57fa6c61ce47b039bf50727ed8e Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Mon, 7 Sep 2015 09:49:18 +0100 Subject: [PATCH] Redone backup dir struc for subdirs & efficiency Now establishes path from base and if full path doesn't exist, it fills in the blanks, including sub-dir structure to file from base. --- lib/file-control-xhr.php | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/file-control-xhr.php b/lib/file-control-xhr.php index 0294e91..a0dc576 100644 --- a/lib/file-control-xhr.php +++ b/lib/file-control-xhr.php @@ -247,20 +247,27 @@ if (!$error && $_GET['action']=="save") { } // Save a version controlled backup source of the file - $backupDirBase = isset($ftpSite) ? parse_url($ftpSite,PHP_URL_HOST) : "localhost"; - $backupDirBase = str_replace("\\","/",dirname(__FILE__))."/../backups/".$backupDirBase; - // Make the base dir for our backup if it doesn't exist - if (!is_dir($backupDirBase)) { - mkdir($backupDirBase); + // Establish the base, host and date dir parts... + $backupDirBase = str_replace("\\","/",dirname(__FILE__))."/../backups/"; + $backupDirHost = isset($ftpSite) ? parse_url($ftpSite,PHP_URL_HOST) : "localhost"; + $backupDirDate = date("M")."-".date("d")."-".date("Y"); + + // Establish an array of dirs from base to our file location + $subDirsArray = explode("/",ltrim($fileLoc,"/")); + array_unshift($subDirsArray,$backupDirHost,$backupDirDate); + // Make any dirs that don't exist + if (!is_dir($backupDirBase.implode("/",$subDirsArray))) { + $pathIncr = ""; + for ($i=0; $i