Returns filesystem-safe file names.

@param string $fileName
@param bool   $allowMixedCase
@return string
494953
public static function getSafe(string $fileName = '', bool $allowMixedCase = true): string
    {
        $fileName = \iconv('UTF-8', 'ASCII//TRANSLIT', \trim($fileName));
        if (!$allowMixedCase) {
            $fileName = \strtolower($fileName);
        }
        $fileName = \preg_replace('/[^a-z0-9\-\ \.]/i', '', $fileName);
        $fileName = \preg_replace('/[\s\-]+/', '-', $fileName);

        return $fileName;
    }
373627
static function _NormalizeFilename($filename){
		$_filename = "";
		while(1){
			$_filename = preg_replace('/[^\/]+\/+\.\.\//','/',$filename); // "/path/to/dir/../tmp/images/" -> "/path/to/tmp/images/"
			if($_filename==$filename){ break; }
			$filename = $_filename;
		}
		$filename = $_filename;

		$filename = preg_replace('/\/\/+/','/',$filename); // "/path/to//tmp/dir//" -> "/path/to/tmp/dir/"

		return $filename;
	}
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);
    }
307503
public static function convertToFilesystemEncoding($fileName)
    {
        $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
        $encoding = $_config->getFilesystemEncoding();
        if (is_null($encoding) || strcasecmp($encoding, "UTF-8") == 0 || strcasecmp($encoding, "UTF8") == 0) {
            return $fileName;
        }

        if (!function_exists("iconv")) {
            if (strcasecmp($encoding, "ISO-8859-1") == 0 || strcasecmp($encoding, "ISO8859-1") == 0 || strcasecmp($encoding, "Latin1") == 0) {
                return str_replace("\0", "_", utf8_decode($fileName));
            } else if (function_exists('mb_convert_encoding')) {
                /**
                 * @todo check whether charset is supported - mb_list_encodings
                 */
                $encoded = @mb_convert_encoding($fileName, $encoding, 'UTF-8');
                if (@mb_strlen($fileName, "UTF-8") != @mb_strlen($encoded, $encoding)) {
                    return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName));
                }
                else {
                    return str_replace("\0", "_", $encoded);
                }
            } else {
                return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName));
            }
        }

        $converted = @iconv("UTF-8", $encoding . "//IGNORE//TRANSLIT", $fileName);
        if ($converted === false) {
            return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName));
        }

        return $converted;
    }
610293
public static function cleanFilename($filename,$replacement='-'){
		$filename = str_replace("\0",'',$filename);
		$filename = preg_replace('#[^a-zA-Z0-9._-]+#',$replacement,$filename);
		if(strlen($filename)>255){
			$ext = substr($filename,strrpos($filename,'.'));
			$name = substr($filename,0,255-strlen($ext));
			$filename = $name.$ext;
		}
		return $filename;
	}
1009842
public function getMimeType($filename)
    {
        $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));

        if (isset($this->mimeTypes[$extension])) {
            return $this->mimeTypes[$extension];
        }

        return 'text/plain';
    }
46664
public static function sanitizeFileName($filename) {
		if (empty($filename)) return "";
		if (function_exists("mb_ereg_replace")) {
			$filename = mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $filename);
			$filename = mb_ereg_replace("([\.]{2,})", '', $filename);
		} else {
			$filename = preg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $filename);
			$filename = preg_replace("([\.]{2,})", '', $filename);
		}
		return $filename;
	}
1333342
public static function GetTmpFileNameForTableImport($sTableName)
    {
        static $aFileNames = array();
        if (!isset($aFileNames[$sTableName])) {
            $aFileNames[$sTableName] = CMS_TMP_DIR.'/cms_pkg_search_index_'.$sTableName;
        }

        return $aFileNames[$sTableName];
    }
62500
public static function secureFileName($fileName)
    {
      $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
      $fileName = str_replace(array(":", "*", "?", "|", "/"), "_", $fileName);
      if ( $_config->getDisallowUnsafeCharacters() )
      {
        $fileName = str_replace(";", "_", $fileName);
      }
      if ($_config->forceAscii())
      {
        $fileName = CKFinder_Connector_Utils_FileSystem::convertToAscii($fileName);
      }
      return $fileName;
    }
1074739
public function getLanguageFile(string $fileName, bool $useDefaultLocale = false)
    {
        // Check the input file name
        if (!$this->checkFileName($fileName)) {
            throw new InvalidFileNameException("Input file name is not valid.");
        }

        if (!$useDefaultLocale) {
            return $this->translator->get($fileName);
        }

        $currentLocale = $this->getLocale();
        $this->setLocale($this->getDefaultLocale());

        $languageFile = $this->translator->get($fileName);

        $this->setLocale($currentLocale);

        return $languageFile;
    }
601675
protected function checkIfFileNameIsSafe(string $fileName)
    {
        $allowedFileNames = $this->getLanguageFiles(true);

        if (!in_array($fileName, $allowedFileNames)) {
            return false;
        }

        return true;
    }
1012052
protected function extensionOfName($fileName)
    {
        if (mb_strpos($fileName, '.') === false) {
            return mb_strtolower($fileName);
        }

        return mb_strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
    }
46813
public function typeOfName($fileName)
    {
        $this->loadBaseSetIfNotLoaded();
        $extension = $this->extensionOfName($fileName);

        if (isset($this->typeByExtension[$extension])) {
            return $this->typeByExtension[$extension];
        }

        if ($this->extendedSetLoaded) {
            return '';
        }

        $this->loadExtendedSet();

        $this->extendedSetLoaded = true;

        return $this->typeOfName($fileName);
    }
111994
protected function getFileName(string $fileName): ?string
    {
        if (!$fileName) {
            return null;
        }

        if (filter_var($fileName, FILTER_VALIDATE_URL)) {

            try {
                $headers = (get_headers($fileName));
            } catch (Throwable $exception) {
                report($exception);
                sleep(1);

                if ($this->headerCallAttempts < 5) {

                    $this->headerCallAttempts++;

                    return $this->getFileName($fileName);
                }

                throw $exception;
            }

            $this->headerCallAttempts = 0;

            foreach ($headers as $header) {
                if (strpos($header, 'filename')) {
                    $name = explode('filename="', $header);
                    $name = rtrim($name[1], '"');

                    $name = explode('.', $name);

                    if (sizeof($name) > 1) {
                        return str_slug(implode('.', $name));
                    }
                }
            }
        }

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

        $explodedByParams = explode('?', $fileName);
        $fileName = head($explodedByParams);

        $string = sanitizeString(pathinfo($fileName, PATHINFO_FILENAME));

        if (strpos($fileName, '.') !== false && substr($fileName, -3) != 'php') {
            return $string . '.' . pathinfo($fileName, PATHINFO_EXTENSION);
        } else {
            return $string;
        }
    }
20197
public function validNameFile($filename,$ext=true){
        $filename = trim($filename);
        if($filename!="." && $filename!=".." && $filename!=" " && preg_match_all("#^[a-zA-Z0-9-_.\s]+$#",$filename) > 0){
            if($ext) return $this->validExt($filename);
            else return true;
        }else{
            return false;
        }
    }
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);
    }
635670
protected function filename($connectionName)
    {
        $directory = $this->argument('directory');

        if (! empty($directory) &&
            ! is_dir(storage_path($directory))
        ) {
            $dirLoop = '';
            foreach(explode('/', $directory) as $dir) {
                if (! is_dir(storage_path($dirLoop . $dir))) {
                    mkdir(storage_path($dirLoop . $dir));
                }
                $dirLoop .= $dir . DIRECTORY_SEPARATOR;
            }

        }

        $filename = str_slug($connectionName) . '-' . Carbon::now()->format('Y-m-d-H-i-s') . '.sql';

        return storage_path($directory . DIRECTORY_SEPARATOR . $filename);
    }