Makes file name safe for saving

@param string|null $name The name of the file to make safe if different from $this->name
@param string|null $ext The name of the extension to make safe if different from $this->ext
@return string The extension of the file
509220
public function safe($name = null, $ext = null)
    {
        if (!$name) {
            $name = $this->name;
        }
        if (!$ext) {
            $ext = $this->ext();
        }

        return preg_replace("/(?:[^\w\.-]+)/", '_', static::_basename($name, $ext));
    }
800860
public static function genName($ext)
    {
        list($usec, $sec) = explode(" ", microtime());

        $fix = substr($usec, 2, 4);

        return date('YmdHis') . $fix . "." . ltrim($ext, ".");
    }
508540
public function newFileFromName($path, $name, $hashName = false){
        $info = pathinfo($name);
        $ext = isset($info['extension'])? ".{$info['extension']}":"";
        $name = $info['filename'];
        $n = $hashName?md5($name):$name;
        $file = new FileImpl("$path/$n$ext");
        $i = 0;
        while($file->exists()){
            $i++;
            $n = $hashName?md5($name.$i):"$name ($i)";
            $file = new FileImpl("$path/$n$ext");
        }
        return $file;

    }
488232
protected function getName($name)
    {
        $name = parent::getName($name);

        // This fixes any URL encoded filename and sanitize it
        $name = strtolower(urldecode($name));

        // Replace spaces with a dash
        $name = preg_replace('!\s+!', '-', $name);

        // Remove odd characters
        return preg_replace('/[^A-Za-z0-9\-_\.]/', '', $name);
    }
218666
private function name($extra)
    {
        $file = $extra[0];
        $file = str_replace('.', '/', $file);
        //
        switch ($extra[1]) {
            case 'smarty': $extention = '.tpl.php'; break;
            case 'atom': $extention = '.atom'; break;
            default: $extention = '.php'; break;
        }

        return $file.$extention;
    }
1213539
public static function getFilename($name): string
    {
        $originalName = str_replace('\\', '/', $name);
        $pos = strrpos($originalName, '/');
        $originalName = false === $pos ? $originalName : substr($originalName, $pos + 1);

        return $originalName;
    }
754457
public function createDocument($name)
    {
        foreach ($this->registry[DocumentExtension::class] as $extension) {
            $node = $extension->createDocument($this, $name);
            if ($node) {
                return $node;
            }
        }

        return null;
    }
884009
function get_name($class, $function, $name = null)
    {
        $result = false;
        if (isset(Eresus_CMS::getLegacyKernel()->conf['extensions']))
        {
            if (isset(Eresus_CMS::getLegacyKernel()->conf['extensions'][$class]))
            {
                if (isset(Eresus_CMS::getLegacyKernel()->conf['extensions'][$class][$function]))
                {
                    $items = Eresus_CMS::getLegacyKernel()->conf['extensions'][$class][$function];
                    reset($items);
                    $result = isset($items[$name]) ? $name : key($items);
                }
            }
        }

        return $result;
    }
1041792
public function Save ($path, $name = FALSE, $extension = FALSE)
	{
		
		// Set path/name variables
		
		if (!$this->setPath ($path))
		{
			return FALSE;
		}
		
		if ($name)
		{
			$this->name	= $name;
		}
		
		if ($extension)
		{
			$this->extension	= $extension;
		}
		
		$this->filename	= $this->name . '.' . $this->extension;
		
		// Get tmp path
		
		$tmpPath	= $this->tmpPath ();
		
		if (!$tmpPath)
		{
			return FALSE;
		}
		
		// Move the file
		
		if (!move_uploaded_file ($tmpPath, $this->path . $this->filename))
		{
			
			// Set error
			
			new \Sonic\Message ('error', 'Cannot save uploaded file!');
			
			// Return FALSE
			
			return FALSE;
			
		}
		
		// Return TRUE
		
		return TRUE;
		
	}
1092580
public function getFilePath($name, $extension = '.php')
    {
        $filename = trim(dotToPath($name), '/') . $extension;
        $file = null;
        foreach ($this->paths as $dir) {
            $realName = nPath($dir, $filename);
            if (file_exists($realName)) {
                $file = $realName;
                break;
            }
        }
        return $file;
    }
648218
public function getFilenameWithExtension() {
		if ($this->extension === null) {
			return $this->filename;
		}
		else {
			return $this->filename . '.' . $this->extension;
		}
	}
793444
public function getFileName($name,$ext) {

		$fileName = "";
		$dirSep   = DIRECTORY_SEPARATOR;

		// test to see what kind of path was supplied
		$posDash  = strpos($name,"-");
		$posSlash = strpos($name,$dirSep);

		if (($posSlash === false) && ($posDash !== false)) {
			$fileName = $this->getPatternFileName($name);
		} else {
			$fileName = $name;
		}

		if (substr($fileName, 0 - strlen($ext)) !== $ext) {
			$fileName .= $ext;
		}

		return $fileName;

	}
822916
public function getTempFile($keep = false, $ext = null)
    {
        $tmp = tempnam($this->tempPath, "tmp_");
        $tmpExt = '';
        if (!is_null($ext)) {
            $tmpExt .= ".{$ext}";
        }
        if (!$keep) {
            $this->_tempFiles[] = $tmp;
            if (!empty($tmpExt)) {
                $tmp = $tmp . $tmpExt;
                $this->_tempFiles[] = $tmp;
            }
        } else {
            if (!empty($tmpExt)) {
                $tmp = $tmp . $tmpExt;
            }
        }

        return $tmp;
    }
537282
static function changeName($path, $name)
    {
        $f = self::fileInfo($path);
        return $f['dir'].$name.'.'.$f['ext'];
    }
1017030
protected static function _basename($path, $ext = null)
    {
        // check for multibyte string and use basename() if not found
        if (mb_strlen($path) === strlen($path)) {
            return ($ext === null)? basename($path) : basename($path, $ext);
        }

        $splInfo = new SplFileInfo($path);
        $name = ltrim($splInfo->getFilename(), '/\\');

        if ($ext === null || $ext === '') {
            return $name;
        }
        $ext = preg_quote($ext);
        $new = preg_replace("/({$ext})$/u", "", $name);

        // basename of '/etc/.d' is '.d' not ''
        return ($new === '')? $name : $new;
    }
415103
def safe_filename(url)
      url  = url.sub(/\?.*\Z/, '')
      ext  = File.extname(url)
      name = URI.unescape(File.basename(url)).gsub(/[^a-zA-Z0-9_\-.]/, '-').gsub(/-+/, '-')
      File.basename(name, ext).gsub('.', '-') + ext
    end
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;
        }
    }