diff options
author | deva <deva> | 2011-11-01 09:32:21 +0000 |
---|---|---|
committer | deva <deva> | 2011-11-01 09:32:21 +0000 |
commit | 42c62cb041a2b2b95c9cda0c20fcf70334fd244c (patch) | |
tree | 38371eb37ff7348585ee84438b326c25055e2cbe /forum/utils/filehandler.php | |
parent | 208e3b642149a9ac701a43397d31990f9b27ca79 (diff) |
Rewl og krat... needs cleaning up - after port to GIT.origin
Diffstat (limited to 'forum/utils/filehandler.php')
-rw-r--r-- | forum/utils/filehandler.php | 59 |
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&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&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 |