-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFolder.php
More file actions
68 lines (60 loc) · 1.7 KB
/
Folder.php
File metadata and controls
68 lines (60 loc) · 1.7 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
<?php
class WS_Folder {
public function remove($path) {
if (!is_dir($path)) {
return false;
}
if (!preg_match("/\\/$/", $path)) {
$path .= '/';
}
chmod($path, 0777);
self::create($path);
$dh = opendir($path);
while (($file = readdir($dh)) !== false) {
if ($file == '.' || $file == '..') {
continue;
}
if (is_dir($path . $file)) {
chmod($path, 0777);
mkdir($path, 0777, true);
$this->remove($path . $file);
} else if (is_file($path . $file)) {
chmod($path . $file, 0777);
unlink($path . $file);
}
}
closedir($dh);
rmdir($path);
return true;
}
public function create($path) {
if (!is_dir($path)):
mkdir($path);
endif;
}
public function read($path, $return = NULL) {
if (!is_dir($path)) {
return false;
}
if (!preg_match("/\\/$/", $path)) {
$path .= '/';
}
$dh = opendir($path);
while (($file = readdir($dh)) !== false) {
if ($file == '.' || $file == '..') {
continue;
}
if (is_dir($path . $file)) {
$this->read($path . $file, $return);
} else if (is_file($path . $file)) {
$retorno['path'] = $path;
$retorno['file'] = $file;
$retorno['real_path'] = $path . $file;
$return[] = $retorno;
}
}
if (isset($return)):
return $return;
endif;
}
}