ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
SuffixDefinitions.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27{
31 public const SEC = ".sec";
32 protected array $white_list = [];
33
37 public function __construct(array $white_list, protected array $black_list)
38 {
39 $this->white_list[] = '';
40 $this->white_list = array_unique($white_list);
41 }
42
46 public function getWhiteList(): array
47 {
48 return $this->white_list;
49 }
50
54 public function getBlackList(): array
55 {
56 return $this->black_list;
57 }
58
62 public function getValidFileName(string $filename): string
63 {
64 if ($this->hasValidFileName($filename)) {
65 return $filename;
66 }
67 $pi = pathinfo($filename);
68 // if extension is not in white list, remove all "." and add ".sec" extension
69 $basename = str_replace(".", "", $pi["basename"]);
70 if (trim($basename) === "") {
71 throw new \RuntimeException("Invalid upload filename.");
72 }
73 $basename .= self::SEC;
74 if ($pi["dirname"] != "" && ($pi["dirname"] !== "." || str_starts_with($filename, "./"))) {
75 return $pi["dirname"] . "/" . $basename;
76 }
77 return $basename;
78 }
79
83 public function hasValidFileName(string $filename): bool
84 {
85 $pi = pathinfo($filename);
86
87 return in_array(strtolower($pi["extension"]), $this->white_list)
88 && !in_array(strtolower($pi["extension"]), $this->black_list);
89 }
90}
$filename
Definition: buildRTE.php:78
__construct(array $white_list, protected array $black_list)