public static function getUniqFilename($filename = '', $dir = null, $force_file = true, $extension = 'txt')
    {
        if (empty($filename)) {
            return '';
        }
        $extension = trim($extension, '.');

        if (empty($filename)){
            $filename = uniqid();
            if ($force_file) $filename .= '.'.$extension;
        }
        if (is_null($dir)) {
            $dir = defined('_DIR_TMP') ? _DIR_TMP : '/tmp';
        }
        $dir = Directory::slashDirname($dir);
        $_ext = self::getExtension($filename, true);
        $_fname = str_replace($_ext, '', $filename);
        $i = 0;
        while (file_exists($dir.$_fname.$_ext)) {
            $_fname .= ($i==0 ? '_' : '').rand(10, 99);
            $i++;
        }
        return $_fname.$_ext;
    }