Check filename for duplicates, returning a new filename appended with _#

@param  string $file
@return string
510628
public function checkFilename($file)
    {
        $newFilename  = $file;
        $parts        = pathinfo($file);
        $origFilename = $parts['filename'];
        $ext          = (isset($parts['extension']) && ($parts['extension'] != '')) ? '.' . $parts['extension'] : null;

        $i = 1;

        while (file_exists($this->uploadDir . DIRECTORY_SEPARATOR . $newFilename)) {
            $newFilename = $origFilename . '_' . $i . $ext;
            $i++;
        }

        return $newFilename;
    }
986836
public function getUniqueFilename()
	{
		$pathInfo = pathinfo($this->filename);
		$filename = $pathInfo['filename'];
		$extension = $pathInfo['extension'];
		$increment = 1;
		while($this->fileExists($filename . "_" . $increment, $extension))
		{
			$increment++;
		}
		$this->filename = $filename . "_" . $increment . '.' . $extension;

		return $this;
	}
727688
protected function getCacheHash($file)
	{
		$fs_class = explode('\\', get_class($this->fs));
		return $this->f3->hash($this->f3->stringify($file)).
			'.'.strtolower(array_pop($fs_class)).'.meta';
	}
1140156
protected static function getFiles($file)
    {
        if (empty($file)) {
            throw new InvalidArgumentException('There is not any file defined');
        }

        if (is_string($file)) {
            if (!is_file($file)) {
                throw new InvalidArgumentException("'$file' is not a valid file");
            }

            if (!is_readable($file)) {
                throw new InvalidArgumentException("'$file' is not a readable file");
            }

            return [$file];
        }

        if (is_array($file)) {
            $files = [];

            foreach ($file as $f) {
                $files = array_merge($files, self::getFiles($f));
            }

            return $files;
        }

        throw new InvalidArgumentException('The first argument must be string or array');
    }
871239
protected function extractFileName($file)
    {
        if ($file instanceof UploadedFile) {
            return $file->tempName;
        } elseif (is_string($file)) {
            if (file_exists($file)) {
                return $file;
            }
            throw new InvalidParamException("File '{$file}' does not exist.");
        }

        throw new InvalidParamException('Unsupported type of "file" attribute.');
    }
932749
private function getRealFilename(string $file): string
    {
        if (strpos($file, 'vfs://') !== false) {
            return $file;
        }

        return $this->loader->getSourceContext($file)->getPath();
    }
297059
protected function generateSequenceName(UploadedFile $file)
    {
        $index = 1;
        $extension = $file->getClientOriginalExtension();
        $originalName = $file->getClientOriginalName();
        $newName = $originalName.'_'.$index.'.'.$extension;

        while ($this->storage->exists("{$this->getDirectory()}/$newName")) {
            $index++;
            $newName = $originalName.'_'.$index.'.'.$extension;
        }

        return $newName;
    }
525085
public function getFileClassNamespace($file)
    {
        $filenameBlock = explode(DIRECTORY_SEPARATOR, $file);
        $filename = explode('.', end($filenameBlock), 2);
        $filename = reset($filename);

        preg_match('/\snamespace\s+(.+?);/s', file_get_contents($file), $match);

        return    is_array($match) && isset($match[1])
                ? $match[1] . '\\' . $filename
                : false;
    }
586637
public function getNameFromFile($filename)
	{
		$i = strrpos($filename, self::getSlash());

		if ($i!== false)
		{

			return substr($filename, $i+1);
		}
		else
		{
			return $filename;
		}
	}
331321
public static function newName($name)
    {
        if (file_exists($name)) {
            $extension = self::getFileExtension($name);
            $name = substr($name,0,(-strlen($extension)-1)) . '_' . sha1(uniqid(rand(), true)) . ".$extension";
        }
        return $name;
    }
1300809
public function santitizeFileNames($file)
    {
        $path           = pathinfo($file['name']);
        $new_filename   = preg_replace('/.' . $path['extension'] . '$/', '', $file['name']);
        $file['name']   = $this->localLetterSanitize(sanitize_title($new_filename)) . '.' . $path['extension'];
        return $file;
    }
1116000
private function autoNumberFile($path, $file)
    {
        $extension = $file->getClientOriginalExtension();
        $original_name = $file->getClientOriginalName();
        
        $filename = $original_name; // Set to original name
        
        $counter = 1;
        while (file_exists($path . '/' . $filename)) {
            $filename = str_replace("." . $extension, '_' . $counter . "." . $extension, $original_name);
            $counter++;
        }
        
        return $filename;
    }
1133997
public function cleanPath(string $file) : string
  {
    return (substr($file, 0, 1) == DIRECTORY_SEPARATOR ? substr($file, 1) : $file);
  }
570876
public static function file( $file )
	{
		$params = array_merge( static::$params, array(
			'time' => time(),
			'fingerprint' => \CCSession::fingerprint(),
			'random' => CCStr::random(),
		));
		
		foreach( $params as $param => $value )
		{
			$file = str_replace( ':'.$param, $value, $file );
		}
		
		return $file;
	}
583718
protected function getUniqueFilename($fileName)
    {
        $returnValue = uniqid(hash('crc32', $fileName));
    
        $ext = @pathinfo($fileName, PATHINFO_EXTENSION);
        if (!empty($ext)){
            $returnValue .= '.' . $ext;
        }
    
        return $returnValue;
    }
898978
public function getFilename($file)
    {
        // 获取文件的后缀名，因图片从剪贴板里黏贴时后缀名为空，所以此处确保后缀一直存在
        $this->extension = strtolower($file->getClientOriginalExtension()) ?: 'png';

        $randomName = str_random($this->randomLength);

        if ($this->filename) {
            return $this->filename . $this->extension;
        }

        if ($this->filePrefix) {
            return $this->filePrefix . '_' . $randomName . '.' . $this->extension;
        }

        return $randomName . '.' . $this->extension;
    }
497023
public static function getExtension($file){

		$file = trim($file);
		$extension = strtolower(substr(strrchr($file, '.'), 1));

		if($extension == $file){

			return '';
		}
		else{

			return $extension;
		}
	}