36 |
kaklik |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*************************************************************
|
|
|
4 |
* TorrentFlux - PHP Torrent Manager
|
|
|
5 |
* www.torrentflux.com
|
|
|
6 |
**************************************************************/
|
|
|
7 |
/*
|
|
|
8 |
This file is part of TorrentFlux.
|
|
|
9 |
|
|
|
10 |
TorrentFlux is free software; you can redistribute it and/or modify
|
|
|
11 |
it under the terms of the GNU General Public License as published by
|
|
|
12 |
the Free Software Foundation; either version 2 of the License, or
|
|
|
13 |
(at your option) any later version.
|
|
|
14 |
|
|
|
15 |
TorrentFlux is distributed in the hope that it will be useful,
|
|
|
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
18 |
GNU General Public License for more details.
|
|
|
19 |
|
|
|
20 |
You should have received a copy of the GNU General Public License
|
|
|
21 |
along with TorrentFlux; if not, write to the Free Software
|
|
|
22 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
include_once("config.php");
|
|
|
26 |
include_once("functions.php");
|
|
|
27 |
|
|
|
28 |
checkUserPath();
|
|
|
29 |
|
|
|
30 |
// Setup some defaults if they are not set.
|
|
|
31 |
$del = getRequestVar('del');
|
|
|
32 |
$down = getRequestVar('down');
|
|
|
33 |
$tar = getRequestVar('tar');
|
|
|
34 |
$dir = stripslashes(urldecode(getRequestVar('dir')));
|
|
|
35 |
|
|
|
36 |
// Are we to delete something?
|
|
|
37 |
if ($del != "")
|
|
|
38 |
{
|
|
|
39 |
$current = "";
|
|
|
40 |
// The following lines of code were suggested by Jody Steele jmlsteele@stfu.ca
|
|
|
41 |
// this is so only the owner of the file(s) or admin can delete
|
|
|
42 |
if(IsAdmin($cfg["user"]) || preg_match("/^" . $cfg["user"] . "/",$del))
|
|
|
43 |
{
|
|
|
44 |
// Yes, then delete it
|
|
|
45 |
|
|
|
46 |
// we need to strip slashes twice in some circumstances
|
|
|
47 |
// Ex. If we are trying to delete test/tester's file/test.txt
|
|
|
48 |
// $del will be "test/tester\\\'s file/test.txt"
|
|
|
49 |
// one strip will give us "test/tester\'s file/test.txt
|
|
|
50 |
// the second strip will give us the correct
|
|
|
51 |
// "test/tester's file/test.txt"
|
|
|
52 |
|
|
|
53 |
$del = stripslashes(stripslashes($del));
|
|
|
54 |
|
|
|
55 |
if (!ereg("(\.\.\/)", $del))
|
|
|
56 |
{
|
|
|
57 |
avddelete($cfg["path"].$del);
|
|
|
58 |
|
|
|
59 |
$arTemp = explode("/", $del);
|
|
|
60 |
if (count($arTemp) > 1)
|
|
|
61 |
{
|
|
|
62 |
array_pop($arTemp);
|
|
|
63 |
$current = implode("/", $arTemp);
|
|
|
64 |
}
|
|
|
65 |
AuditAction($cfg["constants"]["fm_delete"], $del);
|
|
|
66 |
}
|
|
|
67 |
else
|
|
|
68 |
{
|
|
|
69 |
AuditAction($cfg["constants"]["error"], "ILLEGAL DELETE: ".$cfg['user']." tried to delete ".$del);
|
|
|
70 |
}
|
|
|
71 |
}
|
|
|
72 |
else
|
|
|
73 |
{
|
|
|
74 |
AuditAction($cfg["constants"]["error"], "ILLEGAL DELETE: ".$cfg['user']." tried to delete ".$del);
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
header("Location: dir.php?dir=".urlencode($current));
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
// Are we to download something?
|
|
|
81 |
if ($down != "" && $cfg["enable_file_download"])
|
|
|
82 |
{
|
|
|
83 |
$current = "";
|
|
|
84 |
// Yes, then download it
|
|
|
85 |
|
|
|
86 |
// we need to strip slashes twice in some circumstances
|
|
|
87 |
// Ex. If we are trying to download test/tester's file/test.txt
|
|
|
88 |
// $down will be "test/tester\\\'s file/test.txt"
|
|
|
89 |
// one strip will give us "test/tester\'s file/test.txt
|
|
|
90 |
// the second strip will give us the correct
|
|
|
91 |
// "test/tester's file/test.txt"
|
|
|
92 |
|
|
|
93 |
$down = stripslashes(stripslashes($down));
|
|
|
94 |
|
|
|
95 |
if (!ereg("(\.\.\/)", $down))
|
|
|
96 |
{
|
|
|
97 |
$path = $cfg["path"].$down;
|
|
|
98 |
|
|
|
99 |
$p = explode(".", $path);
|
|
|
100 |
$pc = count($p);
|
|
|
101 |
|
|
|
102 |
$f = explode("/", $path);
|
|
|
103 |
$file = array_pop($f);
|
|
|
104 |
$arTemp = explode("/", $down);
|
|
|
105 |
if (count($arTemp) > 1)
|
|
|
106 |
{
|
|
|
107 |
array_pop($arTemp);
|
|
|
108 |
$current = implode("/", $arTemp);
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
if (file_exists($path))
|
|
|
112 |
{
|
|
|
113 |
header("Content-type: application/octet-stream\n");
|
|
|
114 |
header("Content-disposition: attachment; filename=\"".$file."\"\n");
|
|
|
115 |
header("Content-transfer-encoding: binary\n");
|
|
|
116 |
header("Content-length: " . file_size($path) . "\n");
|
|
|
117 |
|
|
|
118 |
// write the session to close so you can continue to browse on the site.
|
|
|
119 |
session_write_close("TorrentFlux");
|
|
|
120 |
|
|
|
121 |
//$fp = fopen($path, "r");
|
|
|
122 |
$fp = popen("cat \"$path\"", "r");
|
|
|
123 |
fpassthru($fp);
|
|
|
124 |
pclose($fp);
|
|
|
125 |
|
|
|
126 |
AuditAction($cfg["constants"]["fm_download"], $down);
|
|
|
127 |
exit();
|
|
|
128 |
}
|
|
|
129 |
else
|
|
|
130 |
{
|
|
|
131 |
AuditAction($cfg["constants"]["error"], "File Not found for download: ".$cfg['user']." tried to download ".$down);
|
|
|
132 |
}
|
|
|
133 |
}
|
|
|
134 |
else
|
|
|
135 |
{
|
|
|
136 |
AuditAction($cfg["constants"]["error"], "ILLEGAL DOWNLOAD: ".$cfg['user']." tried to download ".$down);
|
|
|
137 |
}
|
|
|
138 |
header("Location: dir.php?dir=".urlencode($current));
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
// Are we to download something?
|
|
|
142 |
if ($tar != "" && $cfg["enable_file_download"])
|
|
|
143 |
{
|
|
|
144 |
$current = "";
|
|
|
145 |
// Yes, then tar and download it
|
|
|
146 |
|
|
|
147 |
// we need to strip slashes twice in some circumstances
|
|
|
148 |
// Ex. If we are trying to download test/tester's file/test.txt
|
|
|
149 |
// $down will be "test/tester\\\'s file/test.txt"
|
|
|
150 |
// one strip will give us "test/tester\'s file/test.txt
|
|
|
151 |
// the second strip will give us the correct
|
|
|
152 |
// "test/tester's file/test.txt"
|
|
|
153 |
|
|
|
154 |
$tar = stripslashes(stripslashes($tar));
|
|
|
155 |
|
|
|
156 |
if (!ereg("(\.\.\/)", $tar))
|
|
|
157 |
{
|
|
|
158 |
// This prevents the script from getting killed off when running lengthy tar jobs.
|
|
|
159 |
ini_set("max_execution_time", 3600);
|
|
|
160 |
$tar = $cfg["path"].$tar;
|
|
|
161 |
|
|
|
162 |
$arTemp = explode("/", $tar);
|
|
|
163 |
if (count($arTemp) > 1)
|
|
|
164 |
{
|
|
|
165 |
array_pop($arTemp);
|
|
|
166 |
$current = implode("/", $arTemp);
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
// Find out if we're really trying to access a file within the
|
|
|
170 |
// proper directory structure. Sadly, this way requires that $cfg["path"]
|
|
|
171 |
// is a REAL path, not a symlinked one. Also check if $cfg["path"] is part
|
|
|
172 |
// of the REAL path.
|
|
|
173 |
if (is_dir($tar))
|
|
|
174 |
{
|
|
|
175 |
$sendname = basename($tar);
|
|
|
176 |
|
|
|
177 |
switch ($cfg["package_type"])
|
|
|
178 |
{
|
|
|
179 |
Case "tar":
|
|
|
180 |
$command = "tar cf - \"".addslashes($sendname)."\"";
|
|
|
181 |
break;
|
|
|
182 |
Case "zip":
|
|
|
183 |
$command = "zip -0r - \"".addslashes($sendname)."\"";
|
|
|
184 |
break;
|
|
|
185 |
default:
|
|
|
186 |
$cfg["package_type"] = "tar";
|
|
|
187 |
$command = "tar cf - \"".addslashes($sendname)."\"";
|
|
|
188 |
break;
|
|
|
189 |
}
|
|
|
190 |
|
|
|
191 |
// HTTP/1.0
|
|
|
192 |
header("Pragma: no-cache");
|
|
|
193 |
header("Content-Description: File Transfer");
|
|
|
194 |
header("Content-Type: application/force-download");
|
|
|
195 |
header('Content-Disposition: attachment; filename="'.$sendname.'.'.$cfg["package_type"].'"');
|
|
|
196 |
|
|
|
197 |
// write the session to close so you can continue to browse on the site.
|
|
|
198 |
session_write_close("TorrentFlux");
|
|
|
199 |
|
|
|
200 |
// Make it a bit easier for tar/zip.
|
|
|
201 |
chdir(dirname($tar));
|
|
|
202 |
passthru($command);
|
|
|
203 |
|
|
|
204 |
AuditAction($cfg["constants"]["fm_download"], $sendname.".".$cfg["package_type"]);
|
|
|
205 |
exit();
|
|
|
206 |
}
|
|
|
207 |
else
|
|
|
208 |
{
|
|
|
209 |
AuditAction($cfg["constants"]["error"], "Illegal download: ".$cfg['user']." tried to download ".$tar);
|
|
|
210 |
}
|
|
|
211 |
}
|
|
|
212 |
else
|
|
|
213 |
{
|
|
|
214 |
AuditAction($cfg["constants"]["error"], "ILLEGAL TAR DOWNLOAD: ".$cfg['user']." tried to download ".$tar);
|
|
|
215 |
}
|
|
|
216 |
header("Location: dir.php?dir=".urlencode($current));
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
if ($dir == "")
|
|
|
220 |
{
|
|
|
221 |
unset($dir);
|
|
|
222 |
}
|
|
|
223 |
|
|
|
224 |
if (isset($dir))
|
|
|
225 |
{
|
|
|
226 |
if (ereg("(\.\.)", $dir))
|
|
|
227 |
{
|
|
|
228 |
unset($dir);
|
|
|
229 |
}
|
|
|
230 |
else
|
|
|
231 |
{
|
|
|
232 |
$dir = $dir."/";
|
|
|
233 |
}
|
|
|
234 |
}
|
|
|
235 |
|
|
|
236 |
DisplayHead(_DIRECTORYLIST);
|
|
|
237 |
?>
|
|
|
238 |
|
|
|
239 |
<script language="JavaScript">
|
|
|
240 |
function MakeTorrent(name_file)
|
|
|
241 |
{
|
|
|
242 |
window.open (name_file,'_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=600,height=430')
|
|
|
243 |
}
|
|
|
244 |
|
|
|
245 |
function ConfirmDelete(file)
|
|
|
246 |
{
|
|
|
247 |
return confirm("<?php echo _ABOUTTODELETE ?>: " + file)
|
|
|
248 |
}
|
|
|
249 |
</script>
|
|
|
250 |
|
|
|
251 |
<?php
|
|
|
252 |
|
|
|
253 |
displayDriveSpaceBar(getDriveSpace($cfg["path"]));
|
|
|
254 |
echo "<br>";
|
|
|
255 |
|
|
|
256 |
if(!isset($dir)) $dir = "";
|
|
|
257 |
ListDirectory($cfg["path"].$dir);
|
|
|
258 |
|
|
|
259 |
DisplayFoot();
|
|
|
260 |
|
|
|
261 |
|
|
|
262 |
//**************************************************************************
|
|
|
263 |
// ListDirectory()
|
|
|
264 |
// This method reads files and directories in the specified path and
|
|
|
265 |
// displayes them.
|
|
|
266 |
function ListDirectory($dirName)
|
|
|
267 |
{
|
|
|
268 |
global $dir, $cfg;
|
|
|
269 |
$bgLight = $cfg["bgLight"];
|
|
|
270 |
$bgDark = $cfg["bgDark"];
|
|
|
271 |
$entrys = array();
|
|
|
272 |
|
|
|
273 |
$bg = $bgLight;
|
|
|
274 |
|
|
|
275 |
$dirName = stripslashes($dirName);
|
|
|
276 |
|
|
|
277 |
if (isset($dir))
|
|
|
278 |
{
|
|
|
279 |
//setup default parent directory URL
|
|
|
280 |
$parentURL = "dir.php";
|
|
|
281 |
|
|
|
282 |
//get the real parentURL
|
|
|
283 |
if (preg_match("/^(.+)\/.+$/",$dir,$matches) == 1)
|
|
|
284 |
{
|
|
|
285 |
$parentURL="dir.php?dir=" . urlencode($matches[1]);
|
|
|
286 |
}
|
|
|
287 |
|
|
|
288 |
echo "<a href=\"" . $parentURL . "\"><img src=\"images/up_dir.gif\" width=16 height=16 title=\""._BACKTOPARRENT."\" border=0>["._BACKTOPARRENT."]</a>";
|
|
|
289 |
}
|
|
|
290 |
|
|
|
291 |
echo "<table cellpadding=2 width=740>";
|
|
|
292 |
$handle = opendir($dirName);
|
|
|
293 |
while($entry = readdir($handle))
|
|
|
294 |
{
|
|
|
295 |
$entrys[] = $entry;
|
|
|
296 |
}
|
|
|
297 |
natsort($entrys);
|
|
|
298 |
|
|
|
299 |
foreach($entrys as $entry)
|
|
|
300 |
{
|
|
|
301 |
if ($entry != "." && $entry != ".." && substr($entry, 0, 1) != ".")
|
|
|
302 |
{
|
|
|
303 |
if (@is_dir($dirName.$entry))
|
|
|
304 |
{
|
|
|
305 |
echo "<tr bgcolor=\"".$bg."\"><td><a href=\"dir.php?dir=".urlencode($dir.$entry)."\"><img src=\"images/folder2.gif\" width=\"16\" height=\"16\" title=\"".$entry."\" border=\"0\" align=\"absmiddle\">".$entry."</a></td>";
|
|
|
306 |
echo "<td> </td>";
|
|
|
307 |
echo "<td> </td>";
|
|
|
308 |
echo "<td align=\"right\">";
|
|
|
309 |
|
|
|
310 |
if ($cfg["enable_maketorrent"])
|
|
|
311 |
{
|
|
|
312 |
echo "<a href=\"JavaScript:MakeTorrent('maketorrent.php?path=".urlencode($dir.$entry)."')\"><img src=\"images/make.gif\" width=16 height=16 title=\"Make Torrent\" border=0></a>";
|
|
|
313 |
}
|
|
|
314 |
|
|
|
315 |
if ($cfg["enable_file_download"])
|
|
|
316 |
{
|
|
|
317 |
echo "<a href=\"dir.php?tar=".urlencode($dir.$entry)."\"><img src=\"images/tar_down.gif\" width=16 height=16 title=\"Download as ".$cfg["package_type"]."\" border=0></a>";
|
|
|
318 |
}
|
|
|
319 |
|
|
|
320 |
// The following lines of code were suggested by Jody Steele jmlsteele@stfu.ca
|
|
|
321 |
// this is so only the owner of the file(s) or admin can delete
|
|
|
322 |
// only give admins and users who "own" this directory
|
|
|
323 |
// the ability to delete sub directories
|
|
|
324 |
if(IsAdmin($cfg["user"]) || preg_match("/^" . $cfg["user"] . "/",$dir))
|
|
|
325 |
{
|
|
|
326 |
echo "<a href=\"dir.php?del=".urlencode($dir.$entry)."\" onclick=\"return ConfirmDelete('".addslashes($entry)."')\"><img src=\"images/delete_on.gif\" width=16 height=16 title=\""._DELETE."\" border=0></a>";
|
|
|
327 |
}
|
|
|
328 |
else
|
|
|
329 |
{
|
|
|
330 |
echo " ";
|
|
|
331 |
}
|
|
|
332 |
echo "</td></tr>\n";
|
|
|
333 |
if ($bg == $bgLight)
|
|
|
334 |
{
|
|
|
335 |
$bg = $bgDark;
|
|
|
336 |
}
|
|
|
337 |
else
|
|
|
338 |
{
|
|
|
339 |
$bg = $bgLight;
|
|
|
340 |
}
|
|
|
341 |
}
|
|
|
342 |
else
|
|
|
343 |
{
|
|
|
344 |
// Do nothing
|
|
|
345 |
}
|
|
|
346 |
}
|
|
|
347 |
}
|
|
|
348 |
closedir($handle);
|
|
|
349 |
|
|
|
350 |
$entrys = array();
|
|
|
351 |
$handle = opendir($dirName);
|
|
|
352 |
while($entry = readdir($handle))
|
|
|
353 |
{
|
|
|
354 |
$entrys[] = $entry;
|
|
|
355 |
}
|
|
|
356 |
natsort($entrys);
|
|
|
357 |
|
|
|
358 |
foreach($entrys as $entry)
|
|
|
359 |
{
|
|
|
360 |
if ($entry != "." && $entry != "..")
|
|
|
361 |
{
|
|
|
362 |
if (@is_dir($dirName.$entry))
|
|
|
363 |
{
|
|
|
364 |
// Do nothing
|
|
|
365 |
}
|
|
|
366 |
else
|
|
|
367 |
{
|
|
|
368 |
$arStat = @lstat($dirName.$entry);
|
|
|
369 |
$arStat[7] = ( $arStat[7] == 0 )? file_size( $dirName . $entry ) : $arStat[7];
|
|
|
370 |
if (array_key_exists(10,$arStat))
|
|
|
371 |
{
|
|
|
372 |
$timeStamp = $arStat[10];
|
|
|
373 |
}
|
|
|
374 |
else
|
|
|
375 |
{
|
|
|
376 |
$timeStamp = "";
|
|
|
377 |
}
|
|
|
378 |
$fileSize = number_format(($arStat[7])/1024);
|
|
|
379 |
// Code added by Remko Jantzen to assign an icon per file-type. But when not
|
|
|
380 |
// available all stays the same.
|
|
|
381 |
$image="images/time.gif";
|
|
|
382 |
$imageOption="images/files/".getExtension($entry).".png";
|
|
|
383 |
if (file_exists("./".$imageOption))
|
|
|
384 |
{
|
|
|
385 |
$image = $imageOption;
|
|
|
386 |
}
|
|
|
387 |
|
|
|
388 |
echo "<tr bgcolor=\"".$bg."\">";
|
|
|
389 |
echo "<td>";
|
|
|
390 |
|
|
|
391 |
// Can users download files?
|
|
|
392 |
if ($cfg["enable_file_download"])
|
|
|
393 |
{
|
|
|
394 |
// Yes, let them download
|
|
|
395 |
echo "<a href=\"dir.php?down=".urlencode($dir.$entry)."\" >";
|
|
|
396 |
echo "<img src=\"".$image."\" width=\"16\" height=\"16\" alt=\"".$entry."\" border=\"0\"></a>";
|
|
|
397 |
echo "<a href=\"dir.php?down=".urlencode($dir.$entry)."\" >".$entry."</a>";
|
|
|
398 |
}
|
|
|
399 |
else
|
|
|
400 |
{
|
|
|
401 |
// No, just show the name
|
|
|
402 |
echo "<img src=\"".$image."\" width=\"16\" height=\"16\" alt=\"".$entry."\" border=\"0\">";
|
|
|
403 |
echo $entry;
|
|
|
404 |
}
|
|
|
405 |
|
|
|
406 |
echo "</td>";
|
|
|
407 |
echo "<td align=\"right\">".$fileSize." KB</td>";
|
|
|
408 |
echo "<td>".date("m-d-Y g:i a", $timeStamp)."</td>";
|
|
|
409 |
echo "<td align=\"right\">";
|
|
|
410 |
|
|
|
411 |
if( $cfg["enable_view_nfo"] && (( substr( strtolower($entry), -4 ) == ".nfo" ) || ( substr( strtolower($entry), -4 ) == ".txt" )) )
|
|
|
412 |
{
|
|
|
413 |
echo "<a href=\"viewnfo.php?path=".urlencode(addslashes($dir.$entry))."\"><img src=\"images/view_nfo.gif\" width=16 height=16 title=\"View '$entry'\" border=0></a>";
|
|
|
414 |
}
|
|
|
415 |
|
|
|
416 |
if ($cfg["enable_maketorrent"])
|
|
|
417 |
{
|
|
|
418 |
echo "<a href=\"JavaScript:MakeTorrent('maketorrent.php?path=".urlencode($dir.$entry)."')\"><img src=\"images/make.gif\" width=16 height=16 title=\"Make Torrent\" border=0></a>";
|
|
|
419 |
}
|
|
|
420 |
|
|
|
421 |
if ($cfg["enable_file_download"])
|
|
|
422 |
{
|
|
|
423 |
// Show the download button
|
|
|
424 |
echo "<a href=\"dir.php?down=".urlencode($dir.$entry)."\" >";
|
|
|
425 |
echo "<img src=\"images/download_owner.gif\" width=16 height=16 title=\"Download\" border=0>";
|
|
|
426 |
echo "</a>";
|
|
|
427 |
}
|
|
|
428 |
|
|
|
429 |
// The following lines of code were suggested by Jody Steele jmlsteele@stfu.ca
|
|
|
430 |
// this is so only the owner of the file(s) or admin can delete
|
|
|
431 |
// only give admins and users who "own" this directory
|
|
|
432 |
// the ability to delete files
|
|
|
433 |
if(IsAdmin($cfg["user"]) || preg_match("/^" . $cfg["user"] . "/",$dir))
|
|
|
434 |
{
|
|
|
435 |
echo "<a href=\"dir.php?del=".urlencode($dir.$entry)."\" onclick=\"return ConfirmDelete('".addslashes($entry)."')\"><img src=\"images/delete_on.gif\" width=16 height=16 title=\""._DELETE."\" border=0></a>";
|
|
|
436 |
}
|
|
|
437 |
else
|
|
|
438 |
{
|
|
|
439 |
echo " ";
|
|
|
440 |
}
|
|
|
441 |
echo "</td></tr>\n";
|
|
|
442 |
|
|
|
443 |
if ($bg == $bgLight)
|
|
|
444 |
{
|
|
|
445 |
$bg = $bgDark;
|
|
|
446 |
}
|
|
|
447 |
else
|
|
|
448 |
{
|
|
|
449 |
$bg = $bgLight;
|
|
|
450 |
}
|
|
|
451 |
}
|
|
|
452 |
}
|
|
|
453 |
}
|
|
|
454 |
closedir($handle);
|
|
|
455 |
echo "</table>";
|
|
|
456 |
}
|
|
|
457 |
|
|
|
458 |
// ***************************************************************************
|
|
|
459 |
// ***************************************************************************
|
|
|
460 |
// Checks for the location of the users directory
|
|
|
461 |
// If it does not exist, then it creates it.
|
|
|
462 |
function checkUserPath()
|
|
|
463 |
{
|
|
|
464 |
global $cfg;
|
|
|
465 |
// is there a user dir?
|
|
|
466 |
if (!is_dir($cfg["path"].$cfg["user"]))
|
|
|
467 |
{
|
|
|
468 |
//Then create it
|
|
|
469 |
mkdir($cfg["path"].$cfg["user"], 0777);
|
|
|
470 |
}
|
|
|
471 |
}
|
|
|
472 |
|
|
|
473 |
|
|
|
474 |
// This function returns the extension of a given file.
|
|
|
475 |
// Where the extension is the part after the last dot.
|
|
|
476 |
// When no dot is found the noExtensionFile string is
|
|
|
477 |
// returned. This should point to a 'unknown-type' image
|
|
|
478 |
// time by default. This string is also returned when the
|
|
|
479 |
// file starts with an dot.
|
|
|
480 |
function getExtension($fileName)
|
|
|
481 |
{
|
|
|
482 |
$noExtensionFile="unknown"; // The return when no extension is found
|
|
|
483 |
|
|
|
484 |
//Prepare the loop to find an extension
|
|
|
485 |
$length = -1*(strlen($fileName)); // The maximum negative value for $i
|
|
|
486 |
$i=-1; //The counter which counts back to $length
|
|
|
487 |
|
|
|
488 |
//Find the last dot in an string
|
|
|
489 |
while (substr($fileName,$i,1) != "." && $i > $length) {$i -= 1; }
|
|
|
490 |
|
|
|
491 |
//Get the extension (with dot)
|
|
|
492 |
$ext = substr($fileName,$i);
|
|
|
493 |
|
|
|
494 |
//Decide what to return.
|
|
|
495 |
if (substr($ext,0,1)==".") {$ext = substr($ext,((-1 * strlen($ext))+1)); } else {$ext = $noExtensionFile;}
|
|
|
496 |
|
|
|
497 |
//Return the extension
|
|
|
498 |
return strtolower($ext);
|
|
|
499 |
}
|
|
|
500 |
|
|
|
501 |
?>
|