Create a unique file name on basis of the original one.

@access private
@author Jerome Bogaerts, <jerome@taotesting.com>
@param  string $originalName
@return string
14914
static public function createFileName($originalName)
    {
        $returnValue = uniqid(hash('crc32', $originalName));

        $ext = @pathinfo($originalName, PATHINFO_EXTENSION);
        if (!empty($ext)){
            $returnValue .= '.' . $ext;
        }

        return $returnValue;
    }
778964
protected function encodeFilename($original)
    {
        $cp437 = $this->utf8ToCp($original);
        if ($cp437 === $original) {
            return array($original, '');
        }

        $extra = pack(
            'vvCV',
            0x7075, // tag
            strlen($original) + 5, // length of file + version + crc
            1, // version
            crc32($original) // crc
        );
        $extra .= $original;

        return array($cp437, $extra);
    }
697162
public function setFileName($filename)
  {
    if ($this->isLocked()) {
      return $this->getObj()->setFileName($filename)->setLocked();
    } else {
      return parent::setFileName($filename);
    }
  }
1338183
public function addName(
        $lastName = '',
        $firstName = '',
        $additional = '',
        $prefix = '',
        $suffix = ''
    ) {
        // define values with non-empty values
        $values = array_filter([
            $prefix,
            $firstName,
            $additional,
            $lastName,
            $suffix,
        ]);

        // define filename
        $this->setFilename($values);

        // set property
        $property = $lastName . ';' . $firstName . ';' . $additional . ';' . $prefix . ';' . $suffix;
        $this->setProperty(
            'name',
            'N' . $this->getCharsetString(),
            $property
        );

        // is property FN set?
        if (!$this->hasProperty('FN')) {
            // set property
            $this->setProperty(
                'fullname',
                'FN' . $this->getCharsetString(),
                trim(implode(' ', $values))
            );
        }

        return $this;
    }
22337
private function getUniqueFileName(string $folder, string $fileName, int $counter = 0): string
    {
        $newFileName = $fileName;

        if ($counter > 0) {
            $fileNameParts = explode('.', $fileName, 2);
            $newFileName = $fileNameParts[0] . '-' . $counter;

            if (isset($fileNameParts[1])) {
                $newFileName .= '.' . $fileNameParts[1];
            }
        }

        $filePath = $this->getPathByFolderAndFileName($folder, $newFileName);

        $this->logger->debug('Check FilePath: ' . $filePath);

        if (!$this->filesystem->exists($filePath)) {
            return $newFileName;
        }

        ++$counter;

        return $this->getUniqueFileName($folder, $fileName, $counter);
    }
450886
private function setNewFilename($newfilename = null)
    {
        $extension = $this->results['original_extension'];
        $originalFilename = $this->results['original_filename'];

        $timestamp = Carbon::now()->getTimestamp();

        switch ($this->newfilename) {
            case 'hash':
                $newfilename = md5($originalFilename.$timestamp);
                break;
            case 'random':
                $newfilename = Str::random(16);
                break;
            case 'timestamp':
                $newfilename = $timestamp;
                break;
            case 'custom':
                $newfilename = (! empty($newfilename) ? $newfilename : $originalFilename);
                break;
            default:
                $newfilename = pathinfo($originalFilename, PATHINFO_FILENAME);
        }

        $this->results['basename'] = (string) $newfilename;
        $this->results['filename'] = $newfilename.'.'.$extension;

        return $this;
    }
356516
public function setName($name) {
        // get the path info of the given name
        $pathinfo = pathinfo($name);
        
        // get the base file name
        $filename = $pathinfo['filename'];
        
        // set the file name
        $this->name = $filename . '.' . $this->extension();

        // done, return the instance of this, to make chaining possible
        return $this;
    }
593415
public function setName($name)
	{
		if ( ! is_string($name)) {
			throw new \InvalidArgumentException(
				__METHOD__."() expects parameter one, name, to be a string"
			);	
		}
		
		if ( ! is_readable($name)) {
			throw new \InvalidArgumentException(
				__METHOD__."() expects parameter one, name, to be a readable filename"
			);
		}
		
		$this->name = $name;
		
		return $this;
	}
1219200
protected function prepareFileName($filename, $extension)
    {
        if ($this->config->get('file_upload_translit', 1)) {
            $filename = $this->language->translit($filename, null);
        }

        $suffix = gplcart_string_random(6);
        $clean = gplcart_file_sanitize($filename);
        return "$clean-$suffix.$extension";
    }
1102914
public function useFilename($filename)
    {
        $this->filename = $this->sanitizeFilename($filename);
        $this->hash_filename = false;

        return $this;
    }
1300212
protected function getUniqueFilename($fileName)
    {
        $value = uniqid(md5($fileName));
        $ext = pathinfo($fileName, PATHINFO_EXTENSION);
        if (!empty($ext)){
            $value .= '.' . $ext;
        }
        return static::FILE_DIR . '/' . $value;
    }
97233
public function extName($extName = null)
    {
        if (func_num_args() > 0) {
            $parts = pathinfo($this->_name);
            $this->_name = "{$parts['dirname']}/{$parts['filename']}.{$extName}";
            return $this;
        }
        return pathinfo($this->_name, PATHINFO_EXTENSION);
    }
610140
protected function setOriginalFilename($originalName) {
		$prefix = "image/" . $this->container_guid . "/";
		$filestorename = elgg_strtolower(time() . $originalName);
		$this->setFilename($prefix . $filestorename);
		$this->originalfilename = $originalName;
	}
515237
def unique_file_name(base_name, extension=''):
    '''
    
    '''
    idcount = 0

    if extension and not extension.startswith('.'):
        extension = '.%s' % extension

    fname = base_name + extension

    while os.path.exists(fname):
        fname = "%s-%d%s" % (base_name, idcount, extension)
        idcount += 1

    return fname
1103291
private function generateFilename()
    {
        $filename = str_random(100) . "." . $this->extension;

        if(Storage::exists($this->folder . '/' . $filename))
        {
            $this->generateFilename();
        }

        return $filename;
    }
466900
private function generateNewFilename()
    {
        $time = time();
        $filename = $this->filename;
        $ext =  end(explode(".", $filename));
        do {
            $filename = substr(md5($filename. $time), 0, 8) . '.' . $ext;
        } while (file_exists($this->uploadDirectory . DIRECTORY_SEPARATOR . $filename));
        return $filename;
    }
200218
function make_filename($filename)
    {
        // Check if it's an absolute or relative path.
        if (pia_substr($filename, 0, 1) != '/') {
            $filename = $this->root . '/' . $filename;
        }

        if (!file_exists($filename)) {
            die("Template->make_filename(): Erreur - Le fichier $filename est inexistant");
        }
        return $filename;
    }