-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup.php
More file actions
60 lines (57 loc) · 1.32 KB
/
backup.php
File metadata and controls
60 lines (57 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<html>
<body>
<?php
echo '<h2>file list:</h2>';
function listfiles($prefix,$basedir,$zip)
{
$dir = $prefix . DIRECTORY_SEPARATOR . $basedir;
$files = scandir($dir);
if(is_bool($files) && !$files)
{
echo "error folder '$dir' not found";
}
else
{
foreach($files as $key => $value)
{
if (!in_array($value,array(".","..")))
{
$path = $dir . DIRECTORY_SEPARATOR . $value;
if(is_dir($path))
{
listfiles($prefix,$basedir . DIRECTORY_SEPARATOR . $value,$zip);
}
else
{
$relative_path = $basedir . DIRECTORY_SEPARATOR . $value;
echo $relative_path . '<br>';
$zip->addFile($path,$relative_path);
}
}
}
}
}
$backup = new ZipArchive();
$name='./temp/backup.zip';
$ok = $backup->open($name,ZIPARCHIVE::CREATE | ZipArchive::OVERWRITE);
if ($ok === TRUE) {
echo "<p><a href='$name' download='$name'>Download archive</a></p><p>";
listfiles('.','temp',$backup);
echo '<p>';
if($backup->close())
{
echo 'archive properly closed';
}
else
{
echo 'problem closing archive';
}
}
else
{
echo "<h3>Error opening archive: $ok</h3>";
var_export($backup);
}
?>
</body>
</html>