forked from phpbb/quickinstall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions_files.php
160 lines (139 loc) · 2.44 KB
/
functions_files.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
<?php
/**
*
* @package quickinstall
* @version $Id$
* @copyright (c) 2007, 2008 eviL3
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
* @ignore
*/
if (!defined('IN_QUICKINSTALL'))
{
exit;
}
/**
* Useful class for directory and file actions
*/
class file_functions
{
public static function delete_file($file)
{
return unlink($file);
}
public static function copy_file($src_file, $dst_file)
{
return copy($src_file, $dst_file);
}
public static function move_file($src_file, $dst_file)
{
self::copy_file($src_file, $dst_file);
self::delete_file($src_file);
}
public static function copy_dir($src_dir, $dst_dir)
{
self::append_slash($src_dir);
self::append_slash($dst_dir);
if (!is_dir($dst_dir))
{
mkdir($dst_dir);
}
foreach (scandir($src_dir) as $file)
{
if (in_array($file, array('.', '..'), true))
{
continue;
}
$src_file = $src_dir . $file;
$dst_file = $dst_dir . $file;
if (is_file($src_file))
{
if (is_file($dst_file))
{
$ow = filemtime($src_file) - filemtime($dst_file);
}
else
{
$ow = 1;
}
if ($ow > 0)
{
if (copy($src_file, $dst_file))
{
touch($dst_file, filemtime($src_file));
}
}
}
else if (is_dir($src_file))
{
self::copy_dir($src_file, $dst_file);
}
}
}
public static function delete_dir($dir, $empty = false)
{
self::append_slash($dir);
if (!file_exists($dir) || !is_dir($dir) || !is_readable($dir))
{
return false;
}
foreach (scandir($dir) as $file)
{
if (in_array($file, array('.', '..'), true))
{
continue;
}
if (is_dir($dir . $file))
{
self::delete_dir($dir . $file);
}
else
{
self::delete_file($dir . $file);
}
}
if (!$empty)
{
@rmdir($dir);
}
}
public static function delete_files($dir, $files_ary, $recursive = true)
{
self::append_slash($dir);
foreach (scandir($dir) as $file)
{
if (in_array($file, array('.', '..'), true))
{
continue;
}
if (is_dir($dir . $file))
{
if ($recursive)
{
self::delete_files($dir . $file, $files_ary, true);
}
}
if (in_array($file, $files_ary, true))
{
if (is_dir($dir . $file))
{
self::delete_dir($dir . $file);
}
else
{
self::delete_file($dir . $file);
}
}
}
}
public static function append_slash(&$dir)
{
if ($dir[strlen($dir) - 1] != '/')
{
$dir .= '/';
}
}
}
?>