19 declare(strict_types=1);
64 if (preg_match(
'/^ph(p[3457]?|t|tml|ar)$/i', $suffix)) {
68 return in_array($suffix, $this->whitelist,
true);
79 if ($this->
isClean($filename)) {
83 $pathInfo = pathinfo($filename);
84 $basename = $pathInfo[
'basename'];
85 $parentPath = $pathInfo[
'dirname'] ===
'.' ?
'' : $pathInfo[
'dirname'];
88 $filename = str_replace(
'.',
'', $basename);
92 if ($parentPath ===
'') {
96 return "$parentPath/$filename";
109 return strtolower(pathinfo($filename, PATHINFO_EXTENSION));
__construct(array $whitelist)
FilenameSanitizerImpl constructor.
static sanitizeFileName(string $filename)
isClean(string $filename)
Checks if the filename is prefixed with a valid whitelisted ending.
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...
sanitize(string $filename)
extractFileSuffix(string $filename)
Extracts the suffix from the given filename.