由于特殊字符混乱,导致图像无法在Wordpress上显示

Nom*_*fat 5 php wordpress special-characters

我的网站感染了恶意软件。清理网站后,我发现由于特殊字符问题,某些wordpress图片没有显示。例如,这是在FTP上显示的图像名称

sandí-a-asd-123.jpg
Run Code Online (Sandbox Code Playgroud)

但是,如果我通过此路径访问URL,仍然无法访问

mysite/imagepath/sandÃ-a-asd-123.jpg
Run Code Online (Sandbox Code Playgroud)

只能通过此路径访问

mysite/imagepath/sandÃ%C2%ADa-asd-123.jpg
Run Code Online (Sandbox Code Playgroud)

现在我该怎么办?我应该更改wordpress DB中的所有图像名称还是应该通过FTP更改名称?

谢谢

小智 0

这个 WordPress 功能对我有用:从图片名称中删除所有特殊字符。希望有帮助:D

在functions.php中添加代码

function sanitize_filename_on_upload($filename) {
$ext = end(explode('.',$filename));
// Replace all weird characters
$sanitized = preg_replace('/[^a-zA-Z0-9-_.]/','', substr($filename, 0, -(strlen($ext)+1)));
// Replace dots inside filename
$sanitized = str_replace('.','-', $sanitized);
return strtolower($sanitized.'.'.$ext);
}

add_filter('sanitize_file_name', 'sanitize_filename_on_upload', 10);
Run Code Online (Sandbox Code Playgroud)