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

  • 2
  • 4,947 views

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

米粒在线
  • 本文由 发表于 2013年4月21日17:36:16
  • 转载请务必保留本文链接:https://www.miliol.org/7154.html
网站建设

WordPress上传文件自动重命名

推荐两段在上传媒体文件时自动重命名的代码。        代码一,按时间重命名 上传文件时会以“年月日时分秒+千位毫秒整数”的格式重命名文件,如“20161023122221765.jpg” ...
匿名

发表评论

匿名网友 填写信息

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

评论:2   其中:访客  2   博主  0
    • 米木文艺 米木文艺 0

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