19 declare(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)) {
71 $pathInfo = pathinfo($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.
static sanitizeFileName(string $filename)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
isClean(string $filename)
Checks if the filename is prefixed with a valid whitelisted ending.
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...
__construct(private array $whitelist)
FilenameSanitizerImpl constructor.
sanitize(string $filename)
extractFileSuffix(string $filename)
Extracts the suffix from the given filename.