-
Notifications
You must be signed in to change notification settings - Fork 0
/
r_cleaner.php
175 lines (104 loc) · 4.11 KB
/
r_cleaner.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
/*
* m4Labs Framework
*/
class cleaner{
public $path;
public $file_types = array();
public $days;
public $jsoncallback;
public function __construct( $jsoncallback='', $file_path='backup/history', $all=true, $days=0, $file_types='*' ){
$this->jsoncallback = $jsoncallback;
if($file_types == '*' && $all == true){
$allAll = "*";
}
$file_types = explode(',',$file_types);
$i = 0;
while($i <= count($file_types)-1){
$this->file_types[] = $file_types[$i];
$this->days = $days;
$i++;
}
$this->path = getcwd()."/".$file_path."/";
if($all == true){
if($allAll == "*"){
$this->cleanThemAll();
}else{
$this->clean_it();
}
}
}
private function clean_it(){
//$this->path = str_replace("\\","/",$this->path); //$this->path
if($handle = @opendir(str_replace("\\","/",$this->path))){
while(false !== ($file = readdir($handle))){
if(is_file(str_replace("\\","/",$this->path).$file)){
$file_info = @pathinfo(str_replace("\\","/",$this->path).$file);
if(isset($file_info['extension']) && in_array(strtolower($file_info['extension']), $this->file_types)){
if( @filemtime(str_replace("\\","/",$this->path).$file) < (time() - ($this->days * 24 * 60 * 60)) ){
@unlink(str_replace("\\","/",$this->path).$file);
}
}
}
}
$respArray = array("response" => "SUCCESS", "data" => array( "message"=>"File cleaning complete!", "command"=>"") );
echo $this->jsoncallback."(".json_encode($respArray).")";
exit;
}else{
$respArray = array("response" => "ERROR", "data" => array( "message"=>"Could not find the specified path!", "command"=>"") );
echo $this->jsoncallback."(".json_encode($respArray).")";
exit;
}
}
public function cleanThemAll(){
if(@chdir(str_replace("\\","/",$this->path))){
$files = glob("*.*");
foreach($files as $file){
if( @filemtime(str_replace("\\","/",$this->path).$file) < (time() - ($this->days * 24 * 60 * 60)) ){
@unlink($file);
}
}
$respArray = array("response" => "SUCCESS", "data" => array( "message"=>"File cleaning complete!", "command"=>"") );
echo $this->jsoncallback."(".json_encode($respArray).")";
exit;
}else{
$respArray = array("response" => "ERROR", "data" => array( "message"=>"Could not find the specified path!", "command"=>"") );
echo $this->jsoncallback."(".json_encode($respArray).")";
exit;
}
}
public function clean($file, $file_path='backup/history', $isMany=false){
$this->path = getcwd()."/".$file_path."/";
if($handle = @opendir(str_replace("\\","/",$this->path))){
if(@unlink(str_replace("\\","/",$this->path).$file)){
if($isMany){
return true;
}else{
$respArray = array("response" => "SUCCESS", "data" => array( "message"=>"File cleaning complete!", "command"=>"") );
echo $this->jsoncallback."(".json_encode($respArray).")";
exit;
}
}else{
$respArray = array("response" => "ERROR", "data" => array( "message"=>"Could not find the specified file!", "command"=>"") );
echo $this->jsoncallback."(".json_encode($respArray).")";
exit;
}
}else{
$respArray = array("response" => "ERROR", "data" => array( "message"=>"Could not find the specified path!", "command"=>"") );
echo $this->jsoncallback."(".json_encode($respArray).")";
exit;
}
}
public function clean2($files, $file_path='backup/history'){
$files = explode(",",$files);
$isMany = true;
foreach($files as $file){
$this->clean($file, $file_path,$isMany);
}
$respArray = array("response" => "SUCCESS", "data" => array( "message"=>"Multiple File cleaning complete!", "command"=>"") );
echo $this->jsoncallback."(".json_encode($respArray).")";
exit;
}
//End Of class
}
?>