summaryrefslogtreecommitdiff
path: root/static/classes/UploadException.class.php
diff options
context:
space:
mode:
authorEric Johansson (neku) <neku@pomf.se>2015-02-05 20:06:08 +0100
committerEric Johansson (neku) <neku@pomf.se>2015-02-05 20:06:08 +0100
commitb816236168e74309be4a298ff0a4644a732dc9f3 (patch)
tree1497dced7d755362dcdfd73b7e11d78b04597f2d /static/classes/UploadException.class.php
parentc359aa20cd0876e1e497aca1ff19e4c54287b6c2 (diff)
parentfd98101d073805fc42474a00bca640a618f99de6 (diff)
Merge pull request #27 from cenci0/master
Minor code refactoring and improvements
Diffstat (limited to 'static/classes/UploadException.class.php')
-rwxr-xr-xstatic/classes/UploadException.class.php45
1 files changed, 45 insertions, 0 deletions
diff --git a/static/classes/UploadException.class.php b/static/classes/UploadException.class.php
new file mode 100755
index 0000000..b1b4839
--- /dev/null
+++ b/static/classes/UploadException.class.php
@@ -0,0 +1,45 @@
+<?php
+
+// Exception class extension from: http://php.net/manual/en/features.file-upload.errors.php#89374
+// Handles files error returning a proper error description
+
+class UploadException extends Exception {
+ public function __construct($code) {
+ $message = $this->codeToMessage($code);
+ parent::__construct($message, 500);
+ }
+
+ private function codeToMessage($code) {
+ switch ($code) {
+ case UPLOAD_ERR_INI_SIZE:
+ $message = "The uploaded file exceeds the upload_max_filesize directive in php.ini";
+ break;
+ case UPLOAD_ERR_FORM_SIZE:
+ $message = "The uploaded file exceeds the MAX_FILE_SIZE directive that was " .
+ "specified in the HTML form";
+ break;
+ case UPLOAD_ERR_PARTIAL:
+ $message = "The uploaded file was only partially uploaded";
+ break;
+ case UPLOAD_ERR_NO_FILE:
+ $message = "No file was uploaded";
+ break;
+ case UPLOAD_ERR_NO_TMP_DIR:
+ $message = "Missing a temporary folder";
+ break;
+ case UPLOAD_ERR_CANT_WRITE:
+ $message = "Failed to write file to disk";
+ break;
+ case UPLOAD_ERR_EXTENSION:
+ $message = "File upload stopped by extension";
+ break;
+
+ default:
+ $message = "Unknown upload error";
+ break;
+ }
+ return $message;
+ }
+}
+
+?> \ No newline at end of file