"OdenseTrack" is a school assignment/project from AspIT https://aspit.dfine.net/odensetrack
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

upload.class.php 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /*
  3. * Handles all uploads
  4. */
  5. class Upload {
  6. // Acceptable filetypes
  7. private $filetypes = ['jpeg', 'jpg', 'png', 'svg', 'gif'];
  8. private function __construct() {
  9. }
  10. public static function handleUpload($file = false) {
  11. $errors = [];
  12. $filename = $file['name'];
  13. $size = $file['size'];
  14. $tempname = $file['tempname'];
  15. $type = $file['type'];
  16. $extension = strtolower(end(explode('.', $filename)));
  17. if (!in_array($extension, $this->filetypes)) {
  18. // Error! This file does not have an acceptable filetype
  19. $errors[] = "Filtype ikke accepteret.";
  20. }
  21. if ($size > 5000000) {
  22. // We accept a max size of 5 megabytes. (not 5 mebibytes)
  23. $errors[] = "Fil for stor.";
  24. }
  25. if (empty($errors)) {
  26. // Do fileupload
  27. $makeUpload = move_uploaded_file($tempname, Config::$file_path);
  28. if (!$makeUpload) {
  29. $errors[] = "Der opstod en fejl under upload af billedet.";
  30. } else {
  31. return true;
  32. }
  33. }
  34. }
  35. }