wordpress 上传附件中文文件名乱码解决办法

  • 2
  • 3,832 views
  • A+

打开wp-admin/includes/file.php文件
找到wp_handle_upload这个函数,按照下面的代码进行修改.主要修改两行

function wp_handle_upload( &$file, $overrides = false, $time = null ) {
//部分代码略去
// Move the file to the uploads dir
//$new_file = $uploads['path'] . "/$filename";
//将上行代码修改为下面的代码,修正中文文件名编码问题
$new_file = $uploads['path'] . "/" . iconv("UTF-8","GB2312",$filename);

//部分代码略去

//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');
}

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前评论:2   其中:访客  2   博主  0

    • avatar 米木文艺 0

      已经变成乱码的怎么办……
      求解答!