[WordPress] 解決不支援 utf-8 環境下中文檔名異常問題

修改 wp-admin/includes/file.php

1
2
3
4
5
6
// 找到這行程式碼(約在306行),並加入iconv
$new_file = $uploads['path'] . "/$filename";
$new_file = iconv('utf-8', 'big5//ignore', $new_file);
// 把這行註解掉(約在322行),以下列程式碼取代
// return apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $type ), 'upload' );
return apply_filters( 'wp_handle_upload', array( 'file' => $uploads['path']."/$filename", 'url' => $url, 'type' => $type ), 'upload' );

 

修改 wp-admin/includes/media.php

1
2
3
// 把這行註解掉(約在2334行),以下列程式碼取代
// $filename = esc_html( basename( $post->guid ) );
$filename = substr($post->guid, strrpos($post->guid,'/')+1);

 

存檔後即生效


Reference: http://www.xyduan.net/

Licensed under CC BY-NC-SA 3.0 TW
comments powered by Disqus