summaryrefslogtreecommitdiffstats
path: root/app/class/form.class.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/class/form.class.php')
-rw-r--r--app/class/form.class.php41
1 files changed, 41 insertions, 0 deletions
diff --git a/app/class/form.class.php b/app/class/form.class.php
index 9f103ba..907c0a2 100644
--- a/app/class/form.class.php
+++ b/app/class/form.class.php
@@ -181,6 +181,47 @@ class Form
/* return */
return count($this->errorlist) == 0;
}
+
+ /*
+ * Handle an uploaded file
+ */
+ function saveFile($file, $maxsize, $allowed_mime, $path, $req = false)
+ {
+ if (isset($file) && !is_null($file))
+ {
+ if ($file['error'] > 0)
+ {
+ $this->logError("An unknown error occurred");
+ return false;
+ }
+
+ if ($file['size'] > $maxsize)
+ {
+ $this->logError("File must be no larger than " . $maxsize . " bytes");
+ return false;
+ }
+
+ if (is_array($allowed_mime) && array_search($file['type'], $allowed_mime) === false)
+ {
+ $this->logError("File type is not supported");
+ return false;
+ }
+
+ if (!move_uploaded_file($file['tmp_name'], $path))
+ {
+ $this->logError("Error saving uploaded file");
+ return false;
+ }
+ }
+
+ else if ($req)
+ {
+ $this->logError("File upload is required");
+ return false;
+ }
+
+ return true;
+ }
}
?>