我遇到了有关重音文件名的问题,并找到了清理文件名的功能,但我不确定这是否会影响数据库中的文件名,还是只重命名文件?
以下是代码:
add_filter('sanitize_file_name', 'sa_sanitize_spanish_chars', 10);
function sa_sanitize_spanish_chars ($filename) {
return remove_accents( $filename );
}
答案 0 :(得分:1)
在功能文件中尝试以下代码。
function sa_sanitize_spanish_chars($filename) {
$ext = end(explode('.',$filename));
$sanitized = preg_replace('/[^a-zA-Z0-9-_.]/','', substr($filename, 0, -(strlen($ext)+1)));
$sanitized = str_replace('.','-', $sanitized);
return strtolower($sanitized.'.'.$ext);
}
add_filter('sanitize_file_name', 'sa_sanitize_spanish_chars', 10);