FckEditor 2.6.4升级手记


说是升级,其实就是把原来的版本替换掉

1.先到www.fckeditor.net上下载fckeditor(html/js包)和fckeditor.net(专用于aspx环境中处理上传的dll包)

2.将fckeditor中"_"开头的文件都删除掉(基本上都是源码和说明性文档,没啥用处)

3.修改fckconfig.js

FCKConfig.DefaultLanguage  = 'zh-cn' ; //改为简体中文
...
var _FileBrowserLanguage = 'aspx' ; // 设置上传处理的服务端语言
var _QuickUploadLanguage = 'aspx' ; // 设置上传处理的服务端语言

4.上传处理

打开 \editor\filemanager\connectors\aspx\config.ascx

修改CheckAuthentication(),这里我改为仅登录后才能上传(当然你可以根据自己的要求来修改,甚至直接返回true都可以,不过这样会有安全问题,任何人都可以直接上传)

private bool CheckAuthentication()
{  
   //return false;     
   return HttpContext.Current.User.Identity.IsAuthenticated;
}

5.扩展FredCK.FCKeditorV2.dll

默认情况下,fckeditor上传后的文件名是不会自动重命名的,而且默认上传后的文件全部在一个目录下,另外不知道为何,2.6.4中居然去掉了上传文件最大尺寸的限制

好了,一一处理,打开FCKeditor.Net_2.6.3.zip下载包中的解决方案

FileBrowser\FileWorkerBase.cs 修改

protected void FileUpload( string resourceType, string currentFolder, bool isQuickUpload )
{
    HttpPostedFile oFile 
= Request.Files[ "NewFile" ];

    
string sFileName = "";

    
if ( oFile == null )
    {
        
this.SendFileUploadResponse( 202, isQuickUpload );
        
return;
    }

//检测文件大小
int _postFileSize = 0;
if (_postFileSize < 1
)
{
if (Request.Cookies["FCKeditor:UserUploadSize"!= null
)
{
    _postFileSize = Convert.ToInt32(this.Request.Cookies["FCKeditor:UserUploadSize"
].Value);
}

if (_postFileSize < 1
)
{

    _postFileSize = Convert.ToInt32(base.Application["FCKeditor:UserUploadSize"
]);
    if (_postFileSize < 1
)
    {
    _postFileSize = Convert.ToInt32(this.Session["FCKeditor:UserUploadSize"
]);
    if (_postFileSize < 1
)
    {
        _postFileSize = Convert.ToInt32(ConfigurationManager.AppSettings["FCKeditor:UserUploadSize"
]);
        if (_postFileSize < 1
)
        {
        _postFileSize = 500;//默认500k大小

        }
    }
    }
}
}


if (oFile.ContentLength > _postFileSize * 1024

{
this.SendFileUploadResponse(101, isQuickUpload,"","","上传文件不得超过 " + _postFileSize + " K"
);
return
;
}


    
// Map the virtual path to the local server path.
    string sServerDir = this.ServerMapFolder( resourceType, currentFolder, isQuickUpload );

    
// Get the uploaded file name.
    sFileName = System.IO.Path.GetFileName( oFile.FileName );
    sFileName 
= this.SanitizeFileName( sFileName ).ToLower();

    
string sExtension = System.IO.Path.GetExtension( oFile.FileName );
    sExtension 
= sExtension.TrimStart( '.' ).ToLower();

//强制把文件名改成Guid.ext形式(当然你也可以自行另定义规则,比如常用的yyyymmddssffff格式)
sFileName = NewComb().ToString().ToLower() + "." + sExtension;

    ...

}

 
Config.cs修改
internal void LoadConfig()
{
    DefaultSettings();

    
// Call the setConfig() function for the configuration file (config.ascx).
    SetConfig();

//上传目录设置,优化级cookie>session>application>web.config
//Cookie
    
// Look for possible UserFilesPath override options.
string userFilesPath = null;
if (HttpContext.Current.Request.Cookies["FCKeditor:UserFilesPath"!= null

{
userFilesPath = HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies["FCKeditor:UserFilesPath"
].Value);
}

// Session

if (userFilesPath == null || userFilesPath.Length == 0)
{                
userFilesPath 
= Session["FCKeditor:UserFilesPath"as string;
}

    
// Application
    if ( userFilesPath == null || userFilesPath.Length == 0 )
        userFilesPath 
= Application[ "FCKeditor:UserFilesPath" ] as string;

    
// Web.config file.
    if ( userFilesPath == null || userFilesPath.Length == 0 )
        userFilesPath 
= System.Configuration.ConfigurationSettings.AppSettings[ "FCKeditor:UserFilesPath" ];

    
// config.asxc
    if ( userFilesPath == null || userFilesPath.Length == 0 )
        userFilesPath 
= this.UserFilesPath;

    
if ( userFilesPath == null || userFilesPath.Length == 0 )
        userFilesPath 
= DEFAULT_USER_FILES_PATH;

    
// Check that the user path ends with slash ("/")
    if ( !userFilesPath.EndsWith( "/" ) )
        userFilesPath 
+= "/";

    userFilesPath 
= this.ResolveUrl( userFilesPath );

//改为自动按yyyy/mm/dd格式生成上传目录 
userFilesPath += DateTime.Now.Year.ToString().PadLeft(4'0'+ "/" + DateTime.Now.Month.ToString().PadLeft(2'0'+ "/" + DateTime.Now.Day.ToString().PadLeft(2'0'+ "/";

    
this.UserFilesPath = userFilesPath;
}
 
说明:解压后zip为原始未做任何修改的版本,AspxDemo里为修改过后的示例
作者:菩提树下的杨过
出处:http://yjmyzz.cnblogs.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/yjmyzz/p/1499585.html