]> jfr.im git - uguu.git/blobdiff - src/Classes/Upload.php
fix bug with more then 2 dots
[uguu.git] / src / Classes / Upload.php
index 79d7ab437b660277738fc51939808dce8a53ded0..e72f0df9d1a8f41d32d4189c27e1af4b8a832330 100644 (file)
@@ -48,7 +48,7 @@ class Upload extends Response
             $hash = sha1_file($file['tmp_name']);
             $this->FILE_INFO = [
                'TEMP_NAME' => $file['tmp_name'],
-               'NAME'      => strip_tags($file['name']),
+               'NAME'      => strip_tags($this->checkNameLength($file['name'])),
                'SIZE'      => $file['size'],
                'SHA1'      => $hash,
                'EXTENSION' => $this->fileExtension($file),
@@ -251,7 +251,8 @@ class Upload extends Response
         return match ($dotCount) {
             0 => null,
             1 => end($extension),
-            2 => $this->doubleDotExtension($extension)
+            2 => $this->doubleDotExtension($extension),
+            default => end($extension)
         };
     }
 
@@ -278,6 +279,14 @@ class Upload extends Response
             throw new Exception('Filetype not allowed.', 415);
         }
     }
+    
+    public function checkNameLength(string $fileName): string {
+        if (strlen($fileName) > 250) {
+            return substr($fileName, 0, 250);
+        } else {
+            return $fileName;
+        }
+    }
 
     /**
      * Generates a random string of characters, checks if it exists in the database,