-
Notifications
You must be signed in to change notification settings - Fork 9
/
fileread-direct.lib.php
executable file
·185 lines (171 loc) · 4.61 KB
/
fileread-direct.lib.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
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
<?php
/*
*
* Filecharger Direct Read Library
* by Zarel of Novawave
*
* CORE FILE - DO NOT DELETE
*
*/
//====================
// Direct-read Functions
//====================
function fm_mklocal($file)
{
global $prepath;
return $prepath.$file;
}
function fm_mkalllocal($files)
{
global $prepath;
if (!count($files)) return $files;
$dir = upOne($files[0]);
$nfiles = array();
foreach ($files as $i => $file)
{
if (upOne($file) != $dir)
{
if (!is_dir('cache/down/local')) mkdir('cache/down/local');
foreach ($files as $i => $file)
{
@copy($prepath.$file,'cache/down/local/'.basename($file));
$files[$i] = 'cache/down/local/'.basename($file);
}
return $files;
}
else $nfiles[$i] = $prepath.$file;
}
return $nfiles;
}
//====================
// File list Functions
//====================
function fm_fastgetfiles($path)
{
$dh = @opendir($GLOBALS['prepath'].$path);
if ($dh === FALSE) return FALSE;
$files = array();
while (false !== ($file = @readdir($dh)))
{
if ($file == '.' || $file == '..') continue; // Skip files not actually in the directory
if (fm_isdir($path.$file) && substr('/'.$path.$file,-1)!='/') $file .= '/'; // directory?
$files[] = $file;
}
@closedir($dh);
return $files;
}
function fm_getfiles($path)
{
$dh = @opendir($GLOBALS['prepath'].$path);
if ($dh === FALSE) return FALSE;
$dirs = array();
$files = array();
while (false !== ($file = @readdir($dh)))
{
if ($file == '.' || $file == '..') continue; // Skip files not actually in the directory
if (fm_isdir($path.$file)) // directory?
$dirs[] = $file.'/';
else if (fm_isfile($path.$file))
$files[] = $file;
}
@closedir($dh);
if ($cnfs == '1')
{
$files = array_merge($dirs,$files); //merge
$dirs = array();
}
if ($carr !== false)
{
if ($files) natcasesort($files);
if ($dirs) natcasesort($dirs);
}
$files = array_merge($dirs,$files); //merge
return $files;
}
function fm_getdfiles($path)
{
$files = fm_getfiles($path);
if ($files === FALSE) return FALSE;
$dfiles = array();
foreach ($files as $file)
$dfiles[] = fm_fileinfo($path.$file);
return $dfiles;
}
function fm_fileinfo($d)
{
$path = $GLOBALS['prepath'].$d;
$file = filefrompath($path);
if (!fm_exists($d)) return FALSE;
$size = filesize($path);
$modified = filemtime($path);
$ext = fext($file);
return array(
// The name of the file (with slashes) - 'example.gif'
'name' => $file,
// The base name of the file (without slashes) - 'example.gif'
'bname' => (endsWith($file,'/')?substr($file,0,-1):$file),
// The ID of the file - 'file_example.gif'
'id' => file2id($file),
// Is it a directory? - FALSE
'isdir' => (filetype($path) == 'dir'),
// File size - 1024
'size' => $size,
// Text file size - '1 KB'
'tsize' => textfilesize($size),
// Modified (Unix timestamp) - 0
'modified' => $modified,
// Modified - 'Jan 1, 1970 12:00:00 AM'
'tmodified' => date("M j, Y g:i:s A",$modified),
// Date Modified - 'Jan 1, 1970'
'tdmodified' => date("M j, Y",$modified),
// Perms - 777
'perms' => substr(sprintf('%o', fileperms($path)), -3),
// Owner - user
'owner' => fileowner($path),
// Group - group
'group' => filegroup($path),
// Extension - 'gif'
'ext' => $ext,
// File icon - 'gif'
'img' => fticon($ext),
// File type - 'GIF Image'
'type' => textfiletype($ext),
// File type ID - '0'
'ft' => ft($ext),
// Is it writable - TRUE
'writable' => fm_iswritable($d),
// Is it a viewable image (an image that can be displayed in a browser)? - TRUE
'isvimg' => isvimg($ext),
// Image size data - {$width, $height, 1, 'height="$height" width="$width"'}
// ['imgsize'][2]: 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF(intel byte order), 8 = TIFF(motorola byte order), 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF, 15 = WBMP, 16 = XBM
'imgsize' => ((isvimg($ext)||$ext=='psd'||$ext=='bmp') && $size<=5242880)?@getimagesize($path):FALSE
);
}
function fm_readdirect()
{
return true;
}
function fm_geturl($d)
{
global $preurl;
return $preurl.$d;
}
function fm_contents($file, $newline = false)
{
global $prepath;
$res = file_get_contents($prepath.$file);
if ($newline) $res = str_replace("\n",$newline,str_replace("\r","",$res));
return $res;
}
function fm_exists($path)
{
return @file_exists($GLOBALS['prepath'].$path);
}
function fm_isfile($path)
{
return @is_file($GLOBALS['prepath'].$path);
}
function fm_isdir($path)
{
return @is_dir($GLOBALS['prepath'].$path);
}