以 UTF8 编码命名文件名

建议选择 safe 方式命名文件名。

经测试,以下修改源码以适应 utf-8 命名方式兼容性也不好。

// 修改\inc\pageutils.php中utf8_encodeFN、utf8_decodeFN两个函数   function utf8_encodeFN($file,$safe=true){
    global $conf;
    //if($conf['fnencode'] == 'utf-8') return $file;
  if($conf['fnencode'] == 'utf-8'){
		if(eregi('win', PHP_OS)){
			$file=mb_convert_encoding($file,"CP936","UTF-8");
		}
		return $file;
	}   if($safe && preg_match('#^[a-zA-Z0-9/_\-\.%]+$#',$file)){
        return $file;
    }   if($conf['fnencode'] == 'safe'){
        return SafeFN::encode($file);
    }   $file = urlencode($file);
    $file = str_replace('%2F','/',$file);
    return $file;
}   function utf8_decodeFN($file){
    global $conf;
    //if($conf['fnencode'] == 'utf-8') return $file;
	if($conf['fnencode'] == 'utf-8'){
		if(eregi('win', PHP_OS)){
			$file=mb_convert_encoding($file,"UTF-8","CP936");
		}
		return $file;
	}   if($conf['fnencode'] == 'safe'){
        return SafeFN::decode($file);
    }   return urldecode($file);
}
Posted in 经验分享.

发表评论