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

修改 wp-admin/includes/file.php

// 找到這行程式碼(約在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

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

 

存檔後即生效

 

參考自 http://www.xyduan.net/