blob: 4c18c38aa87d232718b4e91228f6eb1017b3d6a9 (
plain)
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
|
<?php
function filehandler()
{
global $UTIL_DIR, $task, $_FILES, $FILE_MAX_SIZE, $DATA_DIR;
global $DEFAULT_MIME_TYPE, $MIME_TYPES;
include_once($UTIL_DIR . "/files.php");
$str = "";
$files = new Files($DATA_DIR . "/files.xml");
if($task == "upload") {
if(is_uploaded_file($_FILES['userfile']['tmp_name'])) {
$name = $filename;
if(!$filename) $name = $_FILES['userfile']['name'];
if(filesize($_FILES['userfile']['tmp_name']) <= $FILE_MAX_SIZE) $files->newFile($_FILES['userfile']['tmp_name'], $name);
else $str .= "File is too big " . sprintf("%.0f", filesize($_FILES['userfile']['tmp_name'])/1024).
"kb, max file size: " . sprintf("%.0f", $FILE_MAX_SIZE/1024) . "kb.";
krsort($files->files);
}
}
if($task == "delete" && $fid) {
$files->deleteFile($fid);
}
$str .= "<form class=\"files\" enctype=\"multipart/form-data\" action=\"?mode=filehandler&task=upload\" method=\"post\">";
$str .= "<p>File: <input name=\"userfile\" type=\"file\"></p>\n";
$str .= "<p>Use alternative filename (leave empty to use original filename):<input name=\"filename\" value=\"".$description."\"/></p>\n";
$str .= "<p><button type=\"submit\">Add file</button></p>";
$str .= "</form>";
$str .= $files->show();
return $str;
}
|