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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
<?php
/**
* @version $Header: /cvsroot/bitweaver/_bit_kernel/Attic/preflight_inc.php,v 1.2 2005/06/28 07:45:45 spiderr Exp $
* @package kernel
* @subpackage functions
*/
/**
* * Return system defined temporary directory.
* In Unix, this is usually /tmp
* In Windows, this is usually c:\windows\temp or c:\winnt\temp
* \static
*/
function getTempDir()
{
static $tempdir;
if (!$tempdir)
{
$tempfile = tempnam(false, 'foo');
$tempdir = dirname($tempfile);
@unlink($tempfile);
}
return $tempdir;
}
/**
* * Return true if windows, otherwise false
* \static
*/
function isWindows()
{
static $windows;
if (!isset($windows))
{
$windows = substr(PHP_OS, 0, 3) == 'WIN';
}
return $windows;
}
function mkdir_p($target, $perms = 0777)
{
global $gDebug;
$target;
if (file_exists($target) || is_dir($target))
{
if ($gDebug) echo "mkdir_p() - file already exists $target<br>";
return 0;
}
if (isWindows()) {
} else {
if (substr($target, 0, 1) != '/') {
if ($gDebug) echo "mkdir_p() - prepending with a /<br>";
$target = "/$target";
}
if( ereg('\.\.', $target) ) {
if ($gDebug) echo "mkdir_p() - invalid Unix path $target<br>";
return 0;
}
}
$oldu = umask(0);
if (@mkdir($target, $perms)) {
umask($oldu);
if ($gDebug) echo "mkdir_p() - creating $target<br>";
return 1;
} else {
umask($oldu);
$parent = substr($target, 0, (strrpos($target, '/')));
if ($gDebug) {
echo "mkdir_p() - trying to create parent $parent<br>";
}
if (mkdir_p($parent, $perms)) {
// make the actual target!
@mkdir($target, $perms);
return 1;
}
}
}
/*
function mkdir_p($target, $perms = 0777)
{
global $gDebug;
if (file_exists($target) || is_dir($target))
{
if ($gDebug) echo "mkdir_p() - file already exists $target<br>";
return 0;
}
if (isWindows()) {
} else {
if (substr($target, 0, 1) != '/') {
if ($gDebug) echo "mkdir_p() - prepending with a /<br>";
$target = "/$target";
}
if (ereg('\.\.', $target) || !preg_match("/[-a-zA-Z0-9\._\/]*-space-/", $target)) {
if ($gDebug) echo "mkdir_p() - invalid Unix path $target<br>";
return 0;
}
}
$oldu = umask(0);
if (@mkdir($target, $perms)) {
umask($oldu);
if ($gDebug) echo "mkdir_p() - creating $target<br>";
return 1;
} else {
umask($oldu);
$parent = substr($target, 0, (strrpos($target, '/')));
if ($gDebug) {
echo "mkdir_p() - trying to create parent $parent<br>";
}
if (mkdir_p($parent, $perms)) {
mkdir_p($target, $perms);
}
}
}
*/
/**
* Check minimum PHP version
* @param pVersion is the minimum PHP version required
*/
function chkPhpVersion($pVersion)
{
$this->chkPhpExtension("", $pVersion);
}
/**
* Check minimum PHP extension version
* @param pExtension is the extension name
* @param pVersion is the minimum extension version required
**/
function chkPhpExtension($pExtension, $pVersion)
{
$success = version_compare(phpversion($pExtension), $pVersion, "<");
$pExtension = ($pExtension != "") ? $pExtension : "PHP";
return $success;
}
/**
* Used to check if files are writeable by the webserver
* @param pFile the name of the file to be checked
**/
function isFileWriteable($pFile)
{
$success = 1;
if (!@file_exists($pFile)) {
$success = 0;
$data = "not exist";
} elseif (!@is_file($pFile)) {
$success = 0;
$data = "not file";
} elseif (!@is_writable($pFile)) {
$success = 0;
$data = "not writeable";
}
return $success;
// $data is currently redundant
}
/**
* Used to check if directories are writeable by the webserver
* @param pDir the name of the directory to be checked
**/
function isDirectoryWriteable($pDir)
{
$success = 1;
if (!@file_exists($pDir)) {
$success = 0;
$data = "not exist";
} elseif (!@is_dir($pDir)) {
$success = 0;
$data = "not directory";
} elseif (!@is_writable($pDir)) {
$success = 0;
$data = "not writeable";
}
return $success;
// $data is currently redundant
}
/**
* Used to check php.ini settings
* @param pName setting name
* @param pValue setting value
* @param pComp setting comparison
**/
function chkPhpSetting($pName, $pValue, $pComp='')
{
$actual = ini_get($pName);
eregi("^([0-9]+)[KMG]$", $actual, $x);
$actual = (isset($x)) ? $x[1] : $actual;
switch($pComp) {
case ">=":
$success = ($actual >= $pValue) ? 1 : 0;
break;
default:
$success = ($actual == $pValue) ? 1 : 0;
}
return $success;
// redundant $data = serialize(array("check" => $pValue, "actual" => $actual));
}
?>
|