WordPress上传中文文件名或图片名乱码问题

WordPress上传中文文件名或图片名乱码问题
首先修改一下上传,打开 wp-admin/include/file.php文件,找到
$new_file = $uploads['path'] . "/$filename";
改为

$new_file = $uploads['path'] . '/' . iconv('UTF-8', 'GBK', $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' );
这样就将上传的文件的文件名转换成了GBK编码,服务器就能够正确的认识文件名了。

注:Wordpress对中文支持不是很好,特别是那些插件,很多都没考虑中文因素,所以上传最好还是用英文或数字名称吧


另一种办法:

打开 wp-admin/include/file.php文件,把

     // Move the file to the uploads dir   
    $new_file = $uploads['path'] . "/$filename";
    if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) )
        return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ) );


   改为:
   
// Move the file to the uploads dir   
     $new_file = $uploads['path'] . "/".date_i18n("YmdHis").floor(microtime()*1000).".".$ext;
     if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) )
             return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ) );


   

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值