ILIAS  release_8 Revision v8.24
SuffixDefinitions.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
6
8{
9 public const SEC = ".sec";
10 protected array $white_list = [];
11 protected array $black_list = [];
12
17 public function __construct(array $white_list, array $black_list)
18 {
19 $this->white_list[] = '';
20 $this->white_list = array_unique($white_list);
21 $this->black_list = $black_list;
22 }
23
24 public function getWhiteList(): array
25 {
26 return $this->white_list;
27 }
28
29 public function getBlackList(): array
30 {
31 return $this->black_list;
32 }
33
37 public function getValidFileName(string $filename): string
38 {
39 if ($this->hasValidFileName($filename)) {
40 return $filename;
41 }
42 $pi = pathinfo($filename);
43 // if extension is not in white list, remove all "." and add ".sec" extension
44 $basename = str_replace(".", "", $pi["basename"]);
45 if (trim($basename) == "") {
46 throw new \RuntimeException("Invalid upload filename.");
47 }
48 $basename .= self::SEC;
49 if ($pi["dirname"] != "" && ($pi["dirname"] != "." || substr($filename, 0, 2) == "./")) {
50 $filename = $pi["dirname"] . "/" . $basename;
51 } else {
52 $filename = $basename;
53 }
54 return $filename;
55 }
56
60 public function hasValidFileName(string $filename): bool
61 {
62 $pi = pathinfo($filename);
63
64 return in_array(strtolower($pi["extension"]), $this->white_list)
65 && !in_array(strtolower($pi["extension"]), $this->black_list);
66 }
67}
$filename
Definition: buildRTE.php:78
__construct(array $white_list, array $black_list)