I have this script which backs up a folder full of files, albeit I really I really intend to use it for a folder which has only images in the folder, nothing else
<?php
$timeZone = date_default_timezone_set('Europe/London');
$now = new DateTime();
$dateTimeNow = $now->format("Y-m-d H:i:s");
$_dateBack = date('d-m-Y', strtotime($dateTimeNow));
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form action="backup_files.php" method="POST" enctype="multipart/form-data">
Name for archive: <input type="text" name="name" id="name" value="Backup"><?php echo "-".$_dateBack; ?><br/>
<div>Enter a different name for the archive if necessary</div>
<input type="file" name="files[]" multiple="true" >
<input type="submit" name="submit" value="Add Files/Folder to zip" >
</form>
<?php
if (isset($_POST['submit'])){
$filesArray = $_FILES['files'];
for ($num = 0; $num < count($filesArray['name']); $num++){
$fileName = $filesArray['name'][$num];
$tempName = $filesArray['tmp_name'][$num];
move_uploaded_file($tempName, 'tmp/'.$fileName);
}
$archiveName = $_POST['name']."-".$_dateBack.".zip";
$filesArrayNames = $_FILES['files']['name'];
$zipDir = scandir('zips/');
$error = false;
foreach ($zipDir as $zipDirFile){
if($zipDirFile == $archiveName){
$error = true;
break;
}
if($error == false){
$tmpDir = scandir('tmp/');
$zip = new ZipArchive();
$zip->open('zips/'.$archiveName, ZipArchive::CREATE);
for ($num = 0; $num < count($filesArray['name']); $num++){
$fileName = $filesArray['name'][$num];
foreach ($tmpDir as $tmpDirFile){
if($tmpDirFile == $fileName){
$zip->addFile('tmp/'.$fileName);
echo "Adding $fileName <br />";
}
}
}
$zip->close();
for ($num = 0; $num < count($filesArray['name']); $num++){
$fileName = $filesArray['name'][$num];
foreach ($tmpDir as $tmpDirFile){
if($tmpDirFile == $fileName){
}
}
}
} else {
echo "Name already exists";
}
}
}
?>
</body>
</html>
All I want is to script this so all I do if I don’t change the name of the archive of the file, is press the submit button and it backs up the files in the remote folder, rather than use the browse button, because I want to back up the folder where the images and subfolder are stored on the remote because I will be backing up one folder (and subfolders) where the images are stored, therefore will find this (the browse button) un-necessary since this will be set in stone where the folder is
EDIT
This post has been reformatted by enclosing the code block in 3 backticks
```
on their own lines.