summaryrefslogtreecommitdiff
path: root/forum/utils/filehandler.php
diff options
context:
space:
mode:
Diffstat (limited to 'forum/utils/filehandler.php')
-rw-r--r--forum/utils/filehandler.php59
1 files changed, 31 insertions, 28 deletions
diff --git a/forum/utils/filehandler.php b/forum/utils/filehandler.php
index af1c305..4c18c38 100644
--- a/forum/utils/filehandler.php
+++ b/forum/utils/filehandler.php
@@ -1,36 +1,39 @@
<?php
-include_once($UTIL_DIR . "/files.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");
-$files = new Files($DATA_DIR . "/files.xml");
+ $str = "";
-if($task == "upload") {
+ $files = new Files($DATA_DIR . "/files.xml");
- 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 echo "File is too big " . sprintf("%.0f", filesize($_FILES['userfile']['tmp_name'])/1024).
- "kb, max file size: " . sprintf("%.0f", $FILE_MAX_SIZE/1024) . "kb.";
- }
-}
+ if($task == "upload") {
-if($task == "delete" && $fid) {
- $files->deleteFile($fid);
-}
+ 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&amp;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>";
-$files->show();
+ $str .= $files->show();
-?>
-<form class="files" enctype="multipart/form-data" action="?mode=filehandler&amp;task=upload" method="post">
- <p>
- File: <input name="userfile" type="file">
- </p>
- <p>
- Use alternative filename (leave empty to use original filename):
- <input name="filename" value="<?php echo $description ?>"/>
- </p>
- <p>
- <button type="submit">Add file</button>
- </p>
-</form>
+ return $str;
+} \ No newline at end of file