-
Notifications
You must be signed in to change notification settings - Fork 1
/
se-cron.php
74 lines (67 loc) · 1.75 KB
/
se-cron.php
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
70
71
72
73
74
<?php
// Include the zip function
include('app/helpers/CreateZipFile.inc.php');
// Define all variables
$usr_path = "upload/";
$dir = get_files($usr_path);
$i = 0;
while($i < count($dir)) :
foreach ($dir as $d) :
$dir_wpath = $usr_path.$d;
if(is_empty($dir_wpath)) :
rmdir($dir_wpath);
; else :
foreach(get_files($dir_wpath) as $f) :
if(file_exists($backup_wpath)) :
unlink($dir_wpath.'/'.$f);
; else :
$outputDir = "backup/"; //Replace "/" with the name of the desired output directory.
$zipName = "backup_" . date('Ymd_His') . ".zip";
$zip = new CreateZipFile;
//Code toZip a directory and all its files/subdirectories
$zip->zipDirectory("upload");
$rand = md5(microtime().rand(0,999999));
$backup_wpath = $outputDir . $zipName;
$fd = fopen($backup_wpath, "wb");
$out = fwrite($fd,$zip->getZippedfile());
fclose($fd);
#$zip->addFile($dir_wpath, $f);
#$zip->save($backup_wpath);
endif;
endforeach;
endif;
endforeach;
$i++;
endwhile;
/**
* Get all files in directory
*
* @param string $path
* @return array
* @author Andrew Smith
*/
function get_files($path){
$content = array();
if(is_dir($path)) :
if($dir = opendir($path)) :
while(false !== ($file = readdir($dir))) :
if($file != '.' && $file != '..' && $file != 'index.html') :
$content[] = $file;
endif;
endwhile;
closedir($dir);
endif;
endif;
return $content;
}
/**
* Check if directory is empty
*
* @param string $dir
* @return void
* @author Andrew Smith
*/
function is_empty($dir){
return (($files = @scandir($dir)) && count($files) <= 2);
}
// End of file