|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+<?php
|
|
|
2
|
+
|
|
|
3
|
+/*
|
|
|
4
|
+ * Handles all uploads
|
|
|
5
|
+ */
|
|
|
6
|
+
|
|
|
7
|
+class Get {
|
|
|
8
|
+
|
|
|
9
|
+ // Acceptable filetypes
|
|
|
10
|
+ private $filetypes = ['jpeg', 'jpg', 'png', 'svg', 'gif'];
|
|
|
11
|
+
|
|
|
12
|
+ private function __construct() {
|
|
|
13
|
+
|
|
|
14
|
+ }
|
|
|
15
|
+
|
|
|
16
|
+ public static function handleUpload($file = false) {
|
|
|
17
|
+ $errors = [];
|
|
|
18
|
+ $filename = $file['name'];
|
|
|
19
|
+ $size = $file['size'];
|
|
|
20
|
+ $tempname = $file['tempname'];
|
|
|
21
|
+ $type = $file['type'];
|
|
|
22
|
+ $extension = strtolower(end(explode('.', $filename)));
|
|
|
23
|
+
|
|
|
24
|
+ if (!in_array($extension, $this->filetypes)) {
|
|
|
25
|
+ // Error! This file does not have an acceptable filetype
|
|
|
26
|
+ $errors[] = "Filtype ikke accepteret.";
|
|
|
27
|
+ }
|
|
|
28
|
+
|
|
|
29
|
+ if ($size > 5000000) {
|
|
|
30
|
+ $errors[] = "Fil for stor.";
|
|
|
31
|
+ }
|
|
|
32
|
+
|
|
|
33
|
+ if (empty($errors)) {
|
|
|
34
|
+ // Do fileupload
|
|
|
35
|
+ }
|
|
|
36
|
+
|
|
|
37
|
+ }
|
|
|
38
|
+
|
|
|
39
|
+}
|