-
Notifications
You must be signed in to change notification settings - Fork 820
/
rmdir.php
45 lines (42 loc) · 1003 Bytes
/
rmdir.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
<?php
//循环删除目录和文件函数
error_reporting(0);
header("Content-Type: text/html;charset=utf-8");
function del_dir($dir){
$n_success = 0;
$n_fail = 0;
if($handle = opendir("$dir")){
while( false !== ($item = readdir($handle))){
if($item != "." && $item != ".."){
if (is_dir("$dir/$item")) {
del_dir("$dir/$item");
}else{
if(unlink("$dir/$item")){
$n_success++;
}else{
$n_fail++;
}
}
}
}
closedir( $handle );
if(rmdir($dir)){
$n_success++;
}else{
$n_fail++;
}
return '删除成功:'.$n_success.',删除失败:'.$n_fail.'!';
}
}
function touch_upload_readme(){
$filepath = './upload/readme.php';
file_put_contents($filepath,"<?php echo \"该目录是上传文件保存,该文件为系统说明文件,请勿删除!\";?>");
}
if($_GET['action'] == 'clean_upload_file'){
echo del_dir("upload");
//重新创建upload目录和readme.php文件
sleep(0.5);
mkdir("upload");
touch_upload_readme();
}
?>