如下所示:
php" id="highlighter_643411">
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
|
function create_folders( $dir ){
return is_dir ( $dir ) or ( create_folders( dirname( $dir ) ) and mkdir ( $dir , 0777) );
}
function mkdirs( $dir , $mode =0777){
if ( is_dir ( $dir ) || @ mkdir ( $dir , $mode )) return true;
if (!mkdirs(dirname( $dir ), $mode )) return false;
return mkdir ( $dir , $mode );
}
//删除多级目录及目录下的文件
function deldir( $dir ) {
//先删除目录下的文件:
$dh =opendir( $dir );
while ( $file =readdir( $dh )) {
if ( $file != "." && $file != ".." ) {
$fullpath = $dir . "/" . $file ;
if (! is_dir ( $fullpath )) {
unlink( $fullpath );
} else {
deldir( $fullpath );
}
}
}
closedir ( $dh );
//删除当前文件夹:
if ( rmdir ( $dir )) {
return true;
} else {
return false;
}
}
|