UTF8 编码时 FCKeditor编辑器上传文件时中文文件名解决方案 [技术论坛 - Article] imag1
Tag: utf8   article   fckeditor   上传   中文文件名   乱码  

正在浏览:   1 名游客






UTF8 编码时 FCKeditor编辑器上传文件时中文文件名解决方案
高级会员
注册日期:
2004/7/16 16:12
所属群组:
注册会员
帖子: 122 | 精华: 3
等级: 10; EXP: 8
HP: 0 / 227
MP: 40 / 2448
离线
Xoops中FCKeditor的上传文件时中文文件名解决方案



使用FCKeditor上传图片、Flash等文件时,文件名中的中文会显示为乱码并在在服务器上面保存有些全部为乱码文件,不能正常显示,在网上搜了一下前辈们的解决方法,没找到很好的解决办法。看来还有N多的人和我一样的困惑,但解决办法又如此的简单:

将 editor\filemanager\browser\default\frmupload.html 文件的编码改为UTF-8即可。

如果不能解决则

编辑upload.php文件

// Compose the file path.

//Modifyed By XuYong 修正UTF-8的问题

$sFileName =iconv("utf-8","gbk",$sFileName);

//End Modifyed

环境XOOPS 2.0.16 UTF-8

2007/4/15 20:18
工具箱 短消息 Email PDF 书签 打印 举报 回顶部


回复: UTF8 编码时 FCKeditor编辑器上传文件时中文文件名解决方案
高级会员
注册日期:
2004/7/16 16:12
所属群组:
注册会员
帖子: 122 | 精华: 3
等级: 10; EXP: 8
HP: 0 / 227
MP: 40 / 2448
离线
另外,上传失败我也找到了一个解决的办法.

也可以到我的blog看看.

2007/4/15 20:43
工具箱 短消息 Email PDF 书签 打印 举报 回顶部


回复: UTF8 编码时 FCKeditor编辑器上传文件时中文文件名解决方案
Support Team
注册日期:
2005/4/30 13:09
来自 安徽安庆
所属群组:
网站管理员
帖子: 471 | 精华: 3
等级: 20; EXP: 9
HP: 0 / 477
MP: 157 / 4048
离线
我当时解决这个问题,很是够戗。
fck一个是绝对路径和相对路径问题有点麻烦。
主要是在editor/filemanager/upload/php/config.php
我将

$Config
['UserFilesPath'] = "/uploads/".$uploadPath."/" ;
$Config['UserFilesAbsolutePath'] = XOOPS_UPLOAD_PATH."/".$uploadPath."/" ;

并在editor/filemanager/upload/php/upload.php
中增加函数
<?php 
/*
 * FCKeditor - The text editor for internet
 * Copyright (C) 2003-2006 Frederico Caldeira Knabben
 * 
 * Licensed under the terms of the GNU Lesser General Public License:
 *         http://www.opensource.org/licenses/lgpl-license.php
 * 
 * For further information visit:
 *         http://www.fckeditor.net/
 * 
 * "Support Open Source software. What about a donation today?"
 * 
 * File Name: upload.php
 *     This is the "File Uploader" for PHP.
 * 
 * File Authors:
 *         Frederico Caldeira Knabben ([email protected])
 */

require('config.php') ;
require(
'util.php') ;

// This is the function that sends the results of the uploading process.
function SendResults$errorNumber$fileUrl ''$fileName ''$customMsg '' )
{
    echo 
'<script type="text/javascript">' ;
    echo 
'window.parent.OnUploadCompleted(' $errorNumber ',"' str_replace'"''\"'$fileUrl ) . '","' str_replace'"''\"'$fileName ) . '", "' str_replace'"''\"'$customMsg ) . '") ;' ;
    echo 
'</script>' ;
    exit ;
}
    function 
mkdir_p($target){
    if (
is_dir($target)||empty($target)) return 1;
    if (
file_exists($target) && !is_dir($target)) return 0;
    if (
mkdir_p(substr($target,0,strrpos($target,'/'))))
        return 
mkdir($target);
    return 
0;
}
// Check if this uploader has been enabled.
if ( !$Config['Enabled'] || ( defined("FCKUPLOAD_DISABLED") && FCKUPLOAD_DISABLED) )
    
SendResults'1''''''This file uploader is disabled. Please check the "editor/filemanager/upload/php/config.php" file' ) ;

// Check if the file has been correctly uploaded.
if ( !isset( $_FILES['NewFile'] ) || is_null$_FILES['NewFile']['tmp_name'] ) || $_FILES['NewFile']['name'] == '' )
    
SendResults'202' ) ;

// Get the posted file.
$oFile $_FILES['NewFile'] ;

// Get the uploaded file name extension.
$sFileName $oFile['name'] ;

// Replace dots in the name with underscores (only one dot can be there... security issue).
if ( $Config['ForceSingleExtension'] )
    
$sFileName preg_replace'/\.(?![^.]*$)/''_'$sFileName ) ;

$sOriginalFileName $sFileName ;

// Get the extension.
$sExtension substr$sFileName, ( strrpos($sFileName'.') + ) ) ;
$sExtension strtolower$sExtension ) ;

// The the file type (from the QueryString, by default 'File').
$sType = isset( $_GET['Type'] ) ? $_GET['Type'] : 'File' ;

// Check if it is an allowed type.
if ( !in_array$sType, array('File','Image','Flash','Media') ) )
    
SendResults1'''''Invalid type specified' ) ;

// Get the allowed and denied extensions arrays.
$arAllowed    $Config['AllowedExtensions'][$sType] ;
$arDenied    $Config['DeniedExtensions'][$sType] ;

// Check if it is an allowed extension.
if ( ( count($arAllowed) > && !in_array$sExtension$arAllowed ) ) || ( count($arDenied) > && in_array$sExtension$arDenied ) ) )
    
SendResults'202' ) ;

$sErrorNumber    '0' ;
$sFileUrl        '' ;

// Initializes the counter used to rename the file, if another one with the same name already exists.
$iCounter ;
$sCreateDir date("Ym");
$Config['UserFilesAbsolutePath']=$Config['UserFilesAbsolutePath'].$sType."/".$sCreateDir."/";
$Config['UserFilesPath'] =$Config['UserFilesPath'].$sType."/".$sCreateDir."/";
// The the target directory.
mkdir_p($Config['UserFilesAbsolutePath']);
if ( isset( 
$Config['UserFilesAbsolutePath'] ) && strlen$Config['UserFilesAbsolutePath'] ) > )
    
$sServerDir $Config['UserFilesAbsolutePath'] ;
else 
    
$sServerDir GetRootPath() . $Config["UserFilesPath"] ;

while ( 
true )
{
    
// Compose the file path.
    //$sFilePath = $sServerDir . $sFileName ;
    
$sFilePath $sServerDir xoops_convert_encoding($sFileName,"gb2312","utf-8") ;
    
// If a file with that name already exists.
    
if ( is_file$sFilePath ) )
    {
        
$iCounter++ ;
        
$sFileName RemoveExtension$sOriginalFileName ) . '(' $iCounter ').' $sExtension ;
        
$sErrorNumber '201' ;
    }
    else
    {
        
move_uploaded_file$oFile['tmp_name'], $sFilePath ) ;

        if ( 
is_file$sFilePath ) )
        {
            
$oldumask umask(0) ;
            
chmod$sFilePath0777 ) ;
            
umask$oldumask ) ;
        }
        
    
//$sFileUrl = $Config["UserFilesPath"] . $sFileName ;
   
$sFileUrl $Config["UserFilesPath"] .urlencode(xoops_convert_encoding($sFileName,"gb2312","utf-8")) ;
        break ;
    }
}

SendResults$sErrorNumber$sFileUrlxoops_convert_encoding($sFileName,"gb2312","utf-8") ) ;
?>


具体案例见lvye.info

2007/7/27 9:26
工具箱 短消息 Email PDF 书签 打印 举报 回顶部


回复: UTF8 编码时 FCKeditor编辑器上传文件时中文文件名解决方案
网站管理员
注册日期:
2005/10/29 13:32
来自 北京
所属群组:
网站管理员
注册会员
ComSupp
推广组
帖子: 2164 | 精华: 24
等级: 38; EXP: 10
HP: 371 / 927
MP: 721 / 6514
离线
下面这篇文章虽然讨论的是asp的情况,不过比较全面,也可参考:
http://blog.csdn.net/itti/archive/2007/04/02/1549292.aspx

2007/8/1 0:08
工具箱 短消息 Email PDF 书签 打印 举报 回顶部


回复: UTF8 编码时 FCKeditor编辑器上传文件时中文文件名解决方案
网站管理员
注册日期:
2005/10/29 13:32
来自 北京
所属群组:
网站管理员
注册会员
ComSupp
推广组
帖子: 2164 | 精华: 24
等级: 38; EXP: 10
HP: 371 / 927
MP: 721 / 6514
离线
我在xoops 2.0.17(xoops svn下载)英文原版、article 1.0的环境下,
对FCKeditor 2.4.3进行了测试,上述各位的方法都不能解决中文名问题,为此,找了一个解决中文名的变通办法:

修改两个文件:
1、FCKeditor\editor\filemanager\browser\default\connectors\php\commands.php
2、FCKeditor\editor\filemanager\upload\php\upload.php

// 在下列代码之后:
// Get the extension.
$sExtension = substr( $sFileName, ( strrpos($sFileName, '.') + 1 ) ) ;
$sExtension = strtolower( $sExtension ) ;

//添加如下语句,则会让所有上传的文件名以“时间+随机数”来重命名。
//Rename filename
$sFileName = date("Ymd_His_").rand(100,200).".".$sExtension;

2007/8/1 3:08
工具箱 短消息 Email PDF 书签 打印 举报 回顶部


回复: UTF8 编码时 FCKeditor编辑器上传文件时中文文件名解决方案
高级会员
注册日期:
2004/7/16 16:12
所属群组:
注册会员
帖子: 122 | 精华: 3
等级: 10; EXP: 8
HP: 0 / 227
MP: 40 / 2448
离线
部署之后发现如果要完美解决中文文件名的问题还要根据服务器环境 文件编码来处理这么转换。

这里要说一下就是xoops.org.cn应该将utf-8和gb2312分开提供,utf-8版本的php文件不使用utf8编码保存会产生一些问题。

2007/8/1 16:50
工具箱 短消息 Email PDF 书签 打印 举报 回顶部





可以查看帖子。
不可发帖。
不可回复。
不可编辑自己的帖子。
不可删除自己的帖子。
不可发起投票调查。
不可在投票调查中投票。
不可上传附件。
不可不经审核直接发帖。
不可使用主题类别。
不可以使用HTML语法。
不可以使用签名档。

[高级搜索]