这是一个众所周知的问题,但由于某种原因,自2013年以来一直没有得到解决
https://core.trac.wordpress.org/ticket/22363
您可以使用
sanitize_file_name
滤器
/**
* Sanitize filename to not brake links with UTF-8 characters
*
* WordPress allow to upload files with names containing UTF-8 characters. Some
* browsers do not handle properly UTF-8 characters in url which causes 404 errors.
* This filter will remove UTF-8 characters from filename before saving it.
*
* @see https://core.trac.wordpress.org/ticket/22363 Bug request
*
* @param string $filename Filename
*
* @return string Sanitized filename
*/
function sanitize_filename( $filename ) {
$file_parts = explode( \'.\', $filename );
$extension = array_pop( $file_parts );
$filename = sanitize_title( preg_replace( \'/[^A-Za-z0-9\\-]/\', \'\', join( \'.\', $file_parts ) ) );
return sprintf(\'%s.%s\', $filename, $extension);
}
add_filter( \'sanitize_file_name\', \'sanitize_filename\' );