Filter uploaded file name

@param string        $sFilename              The filename
@param string        $sVarName               The associated variable name

@return string
340928
protected function filterFilename($sFilename, $sVarName)
    {
        if(($this->fFileFilter))
        {
            $fFileFilter = $this->fFileFilter;
            $sFilename = (string)$fFileFilter($sFilename, $sVarName);
        }
        return $sFilename;
    }
580216
public function queryFile($sFilename)
    {
        $fp = @fopen($sFilename, "r");
        if (!$fp) {
            /** @var Setup $oSetup */
            $oSetup = $this->getInstance("Setup");
            // problems with file
            $oSetup->setNextStep($oSetup->getStep('STEP_DB_INFO'));
            throw new Exception(sprintf($this->getInstance("Language")->getText('ERROR_OPENING_SQL_FILE'), $sFilename), Database::ERROR_OPENING_SQL_FILE);
        }

        $sQuery = fread($fp, filesize($sFilename));
        fclose($fp);

        if (version_compare($this->getDatabaseVersion(), "5") > 0) {
            //disable STRICT db mode if there are set any (mysql >= 5).
            $this->execSql("SET @@session.sql_mode = ''");
        }

        $aQueries = $this->parseQuery($sQuery);
        foreach ($aQueries as $sQuery) {
            $this->execSql($sQuery);
        }
    }
571980
public function urlServeZipped($sObjectIds, $sHash, $sFilename)
    {
        $sUrl = $this->urlServeZippedScheme();

        //  Sub in the values
        $sUrl = str_replace('{{ids}}', $sObjectIds, $sUrl);
        $sUrl = str_replace('{{hash}}', $sHash, $sUrl);
        $sUrl = str_replace('{{filename}}', urlencode($sFilename), $sUrl);

        return $sUrl;
    }
847758
protected static function _streamSafeGlob($sDirectory, $sFilePattern)
    {
        $sDirectory = rtrim($sDirectory, '/');
        $aFiles = scandir($sDirectory);
        $aFound = array();

        foreach ($aFiles as $sFilename) {
            if (fnmatch($sFilePattern, $sFilename)) {
                $aFound[] = $sDirectory . '/' . $sFilename;
            }
        }

        return $aFound;
    }
342433
protected function getFileName (string $fileName)
    {
        if (!$fileName && filter_var ($fileName, FILTER_VALIDATE_URL) === false) {
            return null;
        }

        $explodeFileURL = explode ('/', $fileName);
        $fileName       = end ($explodeFileURL);

        return sanitizeString (pathinfo ($fileName, PATHINFO_FILENAME)) . '.' . pathinfo ($fileName, PATHINFO_EXTENSION);
    }
114745
public function locateName($fileName)
    {
        $list = $this->zip->listContent();
        $listCount = count($list);
        $list_index = -1;
        for ($i = 0; $i < $listCount; ++$i) {
            if (strtolower($list[$i]["filename"]) == strtolower($fileName) ||
                strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) {
                $list_index = $i;
                break;
            }
        }
        return ($list_index > -1);
    }
146343
function isFile( $filename = false )
    {
        if ( !$filename )
            $filename = $this->FileName;
        return $this->doIsFile( $filename );
    }
301779
public function save($filename)
    {
        $this->setFilename($filename);

        call_user_func_array($this->getFunctionName(), [$this->getImage(), $filename]);

        return $filename;
    }
928307
protected final function fileName(string $className): string
    {
        $fileName = "";
        if (array_key_exists($className, $this->className)) {
            $fileName = $this->className[$className];
            $this->removeClass($className);
        }
        return $fileName;
    }
982262
private function getFilenameFromFile(SplFileInfo $file) : string
    {
        return substr($file->getRelativePathname(), 0, -(strlen($this->fileExtension) + 1));
    }
928830
public function pop( $sFileName )
    {
        $sPath = $this->_getCacheFilePath( $sFileName );

        if ( is_null( $sPath ) ) {
            return false;
        }

        if ( $this->_expired( $sPath ) ) {
            @unlink( $sPath );

            return false;
        }

        return unserialize( file_get_contents( $sPath ) );
    }
651660
public function setFilename($filename)
    {
        $filename = $this->filterFilename($filename);

        // Check existing folder path
        $folder = '';
        $parent = $this->Parent();
        if ($parent && $parent->exists()) {
            $folder = $parent->getFilename();
        }

        // Detect change in foldername
        $newFolder = ltrim(dirname(trim($filename, '/')), '.');
        if ($folder !== $newFolder) {
            if (!$newFolder) {
                $this->ParentID = 0;
            } else {
                $parent = Folder::find_or_make($newFolder);
                $this->ParentID = $parent->ID;
            }
        }

        // Update base name
        $this->Name = basename($filename);
        return $this;
    }
652160
public function getUploadFileNames($systemArray=false)
	{
		if ($systemArray)
		{
			return $_FILES;
		}
		else
		{
			$ret = array();
			foreach($_FILES as $file => $property)
			{
				$ret[$file] = $property["name"];
			}
		}
		return $ret;
	}
1309987
public function getNamesWithDifferentExtension(string $fileName)
    {
        if (! file_exists($this->basePath)) {
            return [];
        }

        $extension = pathinfo($fileName, PATHINFO_EXTENSION);

        $baseName = substr($fileName, 0, strlen($fileName) - strlen($extension) - 1);

        $allNames = scandir($this->basePath);

        $namesWithDifferentExtension = array_filter($allNames, function ($existingName) use ($baseName, $extension) {
            $existingExtension = pathinfo($existingName, PATHINFO_EXTENSION);

            $existingBaseName = substr($existingName, 0, strlen($existingName) - strlen($existingExtension) - 1);

            return $existingBaseName === $baseName && $existingExtension !== $extension;
        });

        return array_values($namesWithDifferentExtension);
    }
899186
public function delete($filename)
    {

        $dirname  = pathinfo($filename, PATHINFO_DIRNAME);
        $basename = pathinfo($filename, PATHINFO_BASENAME);

        $file_name = substr($basename, 0, strrpos($basename, '.'));

        $files = $this->storage->files($dirname);

        foreach ($files as $value) {
            $value_basename = pathinfo($value, PATHINFO_BASENAME);
            $name           = substr($value_basename, 0, strrpos($value_basename, '-'));

            if ($name == $file_name) {
                $this->storage->delete($value);
            }
        }

    }
1157725
public function getTemplateNamesForFilename($filename)
    {
        $map = $this->getMap();
        $matching = array_filter(array_keys($map), function ($path) use ($filename) {
            return $filename[0] === $path[0] && 0 === strpos($filename, $path);
        });

        $templateNames = [];
        foreach ($matching as $match) {
            $namespace = $map[$match];
            $templateNames[] = self::MAIN_NAMESPACE === $namespace
                ? ltrim(substr($filename, strlen($match)), '/\\')
                : '@'.$namespace.substr($filename, strlen($match));
        }

        return $templateNames;
    }
45652
public static function getFileNameWithoutExtension($fileName)
    {
        $matches = [];

        if (is_string($fileName) && (bool)preg_match('|(.+)\.(.+)|', $fileName, $matches)) {
            return $matches[1];
        }

        return '';
    }