前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >FckEditor 2.6.4升级手记

FckEditor 2.6.4升级手记

作者头像
菩提树下的杨过
发布2018-01-23 10:39:53
1.1K0
发布2018-01-23 10:39:53
举报

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

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都可以,不过这样会有安全问题,任何人都可以直接上传)

代码语言:js
复制
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 修改

代码语言:js
复制
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修改

代码语言:js
复制
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;
}

源代码下载: http://files.cnblogs.com/yjmyzz/fck2.6.4_Full.rar

说明:解压后zip为原始未做任何修改的版本,AspxDemo里为修改过后的示例

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2009-06-09 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档