19 declare(strict_types=1);
31 public const SEC =
".sec";
37 public function __construct(array $white_list,
protected array $black_list)
39 $this->white_list[] =
'';
40 $this->white_list = array_unique($white_list);
56 return $this->black_list;
67 $pi = pathinfo($filename);
69 $basename = str_replace(
".",
"", $pi[
"basename"]);
70 if (trim($basename) ===
"") {
71 throw new \RuntimeException(
"Invalid upload filename.");
73 $basename .= self::SEC;
74 if ($pi[
"dirname"] !=
"" && ($pi[
"dirname"] !==
"." || str_starts_with($filename,
"./"))) {
75 return $pi[
"dirname"] .
"/" . $basename;
85 $pi = pathinfo($filename);
87 return in_array(strtolower($pi[
"extension"]), $this->white_list)
88 && !in_array(strtolower($pi[
"extension"]), $this->black_list);
__construct(array $white_list, protected array $black_list)
hasValidFileName(string $filename)
getValidFileName(string $filename)