Generate a unique filename.

@param  string|array $filename The filename to alter.
@throws \InvalidArgumentException If the given filename is invalid.
@return string
166583
public function generateUniqueFilename($filename)
    {
        if (!is_string($filename) && !is_array($filename)) {
            throw new \InvalidArgumentException(sprintf(
                'The target must be a string or an array from [pathfino()], received %s',
                (is_object($filename) ? get_class($filename) : gettype($filename))
            ));
        }

        if (is_string($filename)) {
            $info = pathinfo($filename);
        } else {
            $info = $filename;
        }

        $filename = $info['filename'].'-'.uniqid();

        if (isset($info['extension']) && $info['extension']) {
            $filename .= '.'.$info['extension'];
        }

        return $filename;
    }
697162
public function setFileName($filename)
  {
    if ($this->isLocked()) {
      return $this->getObj()->setFileName($filename)->setLocked();
    } else {
      return parent::setFileName($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;
    }
892647
public static function sanitizeFilename($filename) {
        $filename = (string) $filename;

        $strip = array("~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "=", "+", "[", "{", "]", "}", "\\", "|", ";", ":", "\"", "'",
            "&#8216;", "&#8217;", "&#8220;", "&#8221;", "&#8211;", "&#8212;", "â€”", "â€“", ",", "<", ">", "/", "?", "\0");
        $clean = trim(str_replace($strip, '', $filename));
        $clean = preg_replace('/\s+/', "-", $clean);
        if (empty($clean)) {
            throw new CM_Exception_Invalid('Invalid filename.');
        }
        return $clean;
    }
485900
public static function createFromFileGroup($filename)
    {
        if (!file_exists($filename)) {
            throw new \InvalidArgumentException('Invalid file name provided.');
        }
        if (!function_exists('posix_getgrgid')) {
            throw new PosixNotAvailableException(
                'Could not retrieve information about the operating system group because POSIX functions '
                . 'are not available to your PHP executable.'
            );
        }
        if (false === $gid = \filegroup($filename)) {
            throw new \Exception('Could not get the group of the file "' . $filename . '".');
        }
        return new Group($gid);
    }
1353382
public function getLanguageFileKey(string $fileName, string $key)
    {
        // Check the input file name
        if (!$this->checkFileName($fileName)) {
            throw new InvalidFileNameException("Input file name is not valid.");
        }

        return $this->translator->get("$fileName.$key");
    }
1043895
public function getRelativeFilename($filename)
    {
        // strip path from filename
        $result = ltrim(substr($filename, strlen($this->parser->getPath())), DIRECTORY_SEPARATOR);
        if ($result === '') {
            throw new \InvalidArgumentException(
                'File is not present in the given project path: ' . $filename
            );
        }

        return $result;
    }
987037
public function getFilename(string $key): string
    {
        if (!$this->validate($key)) {
            throw new \InvalidArgumentException('The key provided (' . $key . ') is not valid! It may contain only the following characters: "a-z", "0-9", ".", "/", "-" and "_".');
        }
        if ($this->filenameProtocol === null) {
            throw new \Exception('No filenameProtocol specified!');
        }
        return $this->filenameProtocol . '://' . $key;
    }
84341
public function addFile($filename)
    {
        if (file_exists($this->path . $filename) && preg_match('/\.' . $this->type . '$/i', $filename)) {
            $this->files[] = $filename;
        } elseif (!empty($this->domains)) {
            foreach ($this->domains as $domain => $paths) {
                $domainFilename = str_replace($domain, $paths["public"], $filename);
                if (file_exists($domainFilename) && preg_match('/\.' . $this->type . '$/i', $domainFilename)) {
                    $this->files[] = $domainFilename;
                }
            }
        }
        return $this;
    }
400137
protected static function iterateFileName(string $fileName)
    {
        //First remove Extension
        $arrFileParts = explode(".", $fileName);
        $extension = array_pop($arrFileParts);
        $tempFileName = implode(".", $arrFileParts);
        $arrFileName = explode("_", $tempFileName);
        if (is_numeric($arrFileName[(count($arrFileName) - 1)])) {
            $iterator = (int) array_pop($arrFileName);
            $iterator++;
            $arrFileName[] = $iterator;
            $newFileName = implode("_", $arrFileName);
            return $newFileName . "." . $extension;
        }
        return $tempFileName."_1." . $extension;
    }
625412
public function loadFromFile($fileName)
    {
        if (!is_readable($fileName)) {
            throw new \InvalidArgumentException(sprintf('"%s" does not exist or is not readable', $fileName));
        }

        $iterator = new \ArrayIterator([new \SplFileInfo($fileName)]);
        return $this->loadFromIterator($iterator);
    }
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;
    }
463527
public function createRetorno($filename)
    {
        $identifier = new Format\Identifier();

        if (empty($filename)) {
            throw new \InvalidArgumentException('$filename cannot be empty');
        }

        $format = $identifier->identifyFile($filename);

        if (!$format) {
            throw new \Exception('Formato do arquivo não identificado');
        }

        if ($format['tipo'] != 'retorno') {
            throw new \Exception('Este não é um arquivo de retorno');
        }

        if (!$format['banco']) {
            throw new \Exception('Banco não suportado');
        }

        if (!\Cnab\Banco::existBanco($format['banco'])) {
            throw new \Exception('Banco não suportado');
        }

        // por enquanto só suporta o Cnab400

        if ($format['bytes'] == 400) {
            return new Retorno\Cnab400\Arquivo($format['banco'], $filename, $format['layout_versao']);
        } elseif ($format['bytes'] == 240) {
            return new Retorno\Cnab240\Arquivo($format['banco'], $filename, $format['layout_versao']);
        } else {
            throw new \Exception('Formato não suportado');
        }
    }
1045220
public function addTemplate($name, $filename)
    {
        if (!is_string($name) || !is_string($filename) || empty($name) || empty($filename)) {
            throw new \InvalidArgumentException('Template name and filename must be a not empty string');
        }

        $this->templateMap[$name] = $filename;
    }
887554
protected function validateFileName($fileName)
    {
        if (!FileHelper::validatePath($fileName, $this->maxNesting)) {
            throw new ApplicationException(Lang::get('cms::lang.cms_object.invalid_file', [
                'name' => $fileName
            ]));
        }

        if (!strlen(File::extension($fileName))) {
            $fileName .= '.'.$this->defaultExtension;
        }

        return $fileName;
    }
412641
public function getUniqueFilename($filename)
    {
        $uniqueName = uniqid();
        $fileExt    = explode('.', $filename);
        $mimeType   = end($fileExt);
        $filename   = $uniqueName . '.' . $mimeType;

        return $filename;
    }
202824
public function makeValidFileName($sFilename)
    {
        $sFilename = preg_replace('/[\s]+/', '_', $sFilename);
        $sFilename = preg_replace('/[^a-zA-Z0-9_\.-]/', '', $sFilename);

        return str_replace(' ', '_', $sFilename);
    }