简体   繁体   English

由于特殊字符混乱,图像没有显示在wordpress上

[英]Images not showing on wordpress because of special characters mess

My site was infected with malwares. 我的网站感染了恶意软件。 After I cleaned my site, I noticed that some of wordpress images were not showing because of special character issue. 在我清理我的网站后,我注意到由于特殊字符问题,一些wordpress图像没有显示。 For example this is the image name as displayed on FTP 例如,这是FTP上显示的图像名称

sandí-a-asd-123.jpg

But if I access URL through this path it is still not accessible 但是,如果我通过此路径访问URL,它仍然无法访问

mysite/imagepath/sandÃ-a-asd-123.jpg

It is only accessible through this path 它只能通过这条路径访问

mysite/imagepath/sandÃ%C2%ADa-asd-123.jpg

Now what should I do here? 那我该怎么办? Should I change all images names in wordpress DB or should I change names through FTP? 我应该更改wordpress DB中的所有图像名称还是应该通过FTP更改名称?

Thanks 谢谢

This wordpress function works for me: remove all special characters from pic name. 这个wordpress功能适用于我:从pic名称中删除所有特殊字符。 Hope it helps :D 希望它有所帮助:D

add code in functions.php 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM