19declare(strict_types=1);
41 private array $whitelist
53 if (preg_match(
'/^ph(p[3457]?|t|tml|ar)$/i', $suffix)) {
57 return in_array($suffix, $this->whitelist,
true);
67 if ($this->
isClean($filename)) {
72 $basename = $pathInfo[
'basename'];
73 $parentPath = $pathInfo[
'dirname'] ===
'.' ?
'' : $pathInfo[
'dirname'];
75 $filename = str_replace(
'.',
'', $basename);
79 if ($parentPath ===
'') {
83 return "$parentPath/$filename";
95 return strtolower(pathinfo(
$filename, PATHINFO_EXTENSION));
Standard implementation of the filename sanitizing interface.
__construct(private array $whitelist)
FilenameSanitizerImpl constructor.
isClean(string $filename)
Checks if the filename is prefixed with a valid whitelisted ending.
sanitize(string $filename)
@inheritDoc
extractFileSuffix(string $filename)
Extracts the suffix from the given filename.
static sanitizeFileName(string $filename)
The filename sanitizer verifies and fixes file name endings.
const CLEAN_FILE_SUFFIX
This file suffix will be used to sanitize not whitelisted file names.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...