forked from nfocus/kombai
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystem.class.php
More file actions
167 lines (161 loc) · 5.19 KB
/
system.class.php
File metadata and controls
167 lines (161 loc) · 5.19 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
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
<?php
date_default_timezone_set("Asia/Krasnoyarsk");
class System {
public static function getData($path = '<>', $offset = 4, $seek = 0) {
if (!is_file($path) && !file_exists($path)) return false;
$file = fopen($path, 'r');
fseek($file, $seek, 0);
$marker = fread($file, $offset);
fclose($file);
$marker = unpack("H*", $marker);
//echo "$marker[1]<br>";
return $marker[1];
}
public static function checkMediaFile($path = '<>') {
$data = self::getData($path);
return ($data == "3026b275" || $data == "49443303" ||
$data == "52494646" || $data == "52494646");
}
public static function checkImageFile($path = '<>') {
$data = self::getData($path);
return ($data == "ffd8ffe0" || $data == "89504e47" ||
$data == "47494638" || $data == "424d36c4");
}
public static function checkFlashFile($path = '<>') {
$data = self::getData($path);
return ($data == "464c5601" || $data == "25504446");
}
public static function checkAppFile($path = '<>') {
$data = self::getData($path);
return ($data == "4d5a9000" || $data == "4d5a5000");
}
public static function checkTextFile($path = '<>') {
$data = self::getData($path);
return (
//meida file
$data != "3026b275" && $data != "49443303" &&
$data != "52494646" && $data != "52494646" &&
//image file
$data != "ffd8ffe0" && $data != "89504e47" &&
$data != "47494638" && $data != "424d36c4" &&
//flash file
$data != "464c5601" && $data != "25504446" &&
//app file
$data != "4d5a9000" && $data != "4d5a5000" ||
//empty file
$data == null
);
}
public static function getMimeType($path = '<>') {
if (is_dir($path)) return 'folder';
else if (self::checkTextFile($path)) return 'file/text';
else if (self::checkMediaFile($path)) return 'file/media';
else if (self::checkImageFile($path)) return 'file/image';
else if (self::checkFlashFile($path)) return 'file/flash';
else if (self::checkAppFile($path)) return 'file/application';
}
public static function createFile($path = '', $content = '') {
if (file_exists($path)) return;
file_put_contents($path, $content);
}
public static function createFolder($path = '', $mode = 0700) {
if (is_dir($path)) return;
mkdir($path, $mode);
}
public static function getContentFile($path = '<>') {
if (!file_exists($path)) return null;
if (self::checkTextFile($path)) {
return file_get_contents($path);
} else {
$file = fopen($path, 'r');
if (filesize($path)) return fread($file, filesize($path));
else return null;
}
}
public static function getTextContent($path = '<>') {
if (file_exists($path)) return file_get_contents($path);
return null ;
}
public static function putContentFile($path = '', $content = '') {
file_put_contents($path, $content);
}
public static function addContentFile($path = '<>', $content = '') {
if (file_exists($path)) file_put_contents($path, file_get_contents($path).$content);
else file_put_contents($path = '', $content = '');
}
public static function getFileName($path = '<>') {
if (is_file($path)) return basename($path);
return null;
}
public static function getFolderName($path = '<>') {
if (is_file($path)) {
$folder = pathinfo($path);
$path = $folder['dirname'];
}
if (is_dir($path)) {
$path = str_replace(dirname($path), '', $path);
return preg_replace('/^(\/|\\\)/', '', $path);
}
return null;
}
public static function createPath($path = '', $isFile = false) {
$part = explode('/', $path);
$dir = '';
$size = count($part);
for ($i = 0; $i < $size; $i++) {
if ($dir == '') $dir = $part[0];
else $dir = $dir.'/'.$part[$i];
if (!file_exists($dir)) mkdir($dir);
}
if ($isFile && !is_file($dir)) {
rmdir($dir);
fopen($path, 'a');
}
}
public static function removePath($path = '<>') {
if (is_file($path)) {
unlink($path);
} else if(is_dir($path)) {
$folder = escapeshellarg($path);
if (stristr(PHP_OS, 'WIN')) exec("rmdir /s /q $folder");
else exec("rm -rf $folder");
}
}
public static function copyPath($source = '<>', $dest = '<>') {
if ($dest == '') return;
if (is_file($source)) {
copy($source, $dest);
} else if (is_dir($source)) {
if (!is_dir($dest)) mkdir($dest);
$source = escapeshellarg($source);
$dest = escapeshellarg($dest);
if (stristr(PHP_OS, 'WIN')) {
$source = str_replace('/', '\\', $source);
$dest = str_replace('/', '\\', $dest);
exec("xcopy $source $dest /e /y");
} else {
exec("cp -r $source $dest");
}
}
}
public static function movePath($source = '<>', $dest = '<>') {
if (is_file($dest) || is_dir($dest)) {
self::copyPath($source, $dest);
self::removePath($source);
}
}
public static function renamePath($source = '<>', $dest = '<>') {
$source = escapeshellarg($source);
$dest = escapeshellarg($source);
if(is_file($source)) rename($source, $dest);
if (dirname($source) !== dirname($dest)) return;
if (stristr(PHP_OS, 'WIN')) {
$source = str_replace('/', '\\', $source);
$dest = preg_replace('/(.*)(\/|\\\)/', '', $dest);
exec("rename $source $dest");
} else {
exec("mv $source $dest");
}
}
}
?>