zipsite.php
2.02 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
61
62
63
64
65
66
67
68
69
<?php
// GRD ZIP ARCHIVER
// by Piotr GRD
// http://grd.go.pl/
// grd@gazeta.pl
// created 2008-05-05
// free to use and modify as long as you keep info above
// requirements: php zip extensions with ZipArchive class
// SETTINGS
// directory you want to compress with everything inside
// . - for root
// folder - for some folder
// folder/subfolder - for some subfolder
// do not add ending slash
$directory = dirname(__FILE__).DIRECTORY_SEPARATOR;
// the name of your zip archive to be created
$zipfile = '/var/www/reize.com.au/backup/site.zip';
// DO NOT TOUCH BELOW IF YOU DONT KNOW WHAT IT IS
// all the process below
$filenames = array();
// function that browse the directory and all subdirectories inside
$zip = new ZipArchive();
if ($zip->open($zipfile, ZIPARCHIVE::CREATE) !== TRUE) {
exit("cannot open <$zipfile>\n");
}
function browse($dir, $zip) {
// global $filenames;
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && is_file($dir . '/' . $file) && $file != $zipfile) {
$extention = substr($file, -4);
if ($extention != '.log' && $extention != ".zip") {
$filename = $dir . '/' . $file;
echo "Adding " . $dir . '/' . $file . "<br/>";
$zip->addFile($filename, $filename);
}
} else if ($file != "." && $file != ".." && is_dir($dir . '/' . $file)) {
//if ($file == 'newsite' || $file == 'cache' || $file == 'images') {
// } else {
browse($dir . '/' . $file, $zip);
// }
}
}
closedir($handle);
}
return true;
}
browse($directory, $zip);
// creating zip archive, adding browsed files
//foreach ($filenames as $filename) {
// echo "Adding " . $filename . "<br/>";
// $zip->addFile($filename, $filename);
//}
echo "numfiles: " . $zip->numFiles . "\n";
echo "status:" . $zip->status . "\n";
$zip->close();
?>