现在做的项目,用到了编辑器,而FCK都出到了2.6.3所以就把他改成自己想要的,发现跟原来的不一样了,还要重新找,现在就把过程发给大家分享一下吧!

 

一、自定义 FCKeditor 的 BasePath

BasePath 即FCKeditor在网站中的相对路径,默认值是 /fckeditor/,最好在Web.config appSettings中对其进行配置:

<add key="FCKeditor:BasePath" value="/FCKeditor_2.6.3/"/>

这样做有诸多优点:
  1. 开发环境与生产环境不同,开发环境一般是http://localhost/xxx.com/这种情况下FCKeditor就得放在一个虚拟目录http://localhost/fckeditor/中,若涉及多个网站的开发,而各网站的FCKeditor有差别时,这样显然不是最优;
    而且因为物理目录结构与逻辑目录结构不同,也会有发生错误的隐患;
    而如果采用Web.config的配置,就可以在开发环境采用不同的配置,FCKeditor的物理路径与生产环境保持一致;
  2. 当升级FCKeditor时,只需要将新版本的FCKeditor放在相应版本号的目录里,修改一下配置即可。这样可以解决因为静态资源的客户端缓存问题,不同用户出现不同的错误的问题;
  3. 可以直观地看到自己的FCKeditor的版本号。

 

二、配置文件上传的目录

FCKeditor的文件上传(如图片上传)目录可以通过Web.config appSettings进行配置,如:

<add key="FCKeditor:UserFilesPath" value="/UploadFile/FCKeditor/"/>


也可以在 /FCKeditorBasePath/editor/filemanager/connectors/aspx/config.ascx 中进行配置,但我建议 FCKeditor 目录中的内容能不改就不改(fckconfig.js除外),这样日后升级可以放心地替换即可。

 

三、FCKeditor的安全性

在FCKeditor的2.3.2版本里,曾有一个漏洞,可以通过 /editor/filemanager/browser/default/connectors/aspx/connector.aspx 往服务器上传任意文件,我的网站就曾经中招。

2.6.3虽然暂未发现类似的问题,但一般情况下用不到的文件最好还是删除比较好:

  1. FCKeditor BasePath 根目录中除了保留:
    1. /editor
    2. /fckconfig.js
    3. /fckpackager.xml
    4. /fckstyles.xml
    5. /fcktemplates.xml
    6. /license.txt
    外,全部删除

  2. /editor/filemanager/connectors中除了保留:
    1. /aspx/config.ascx
    2. /aspx/upload.aspx
    3. /aspx/connector.aspx
    外,全部删除

  3. 删除 /editor/_source/

  4. /editor/filemanager/connectors/aspx/config.ascx 的 CheckAuthentication() 方法中,增加验证用户是否登录的逻辑

四、上传所有东西按年-月的格式存储

(他的两种上传模式是放在两个目录下的,快捷模式是放在UploadFiles下,而浏览模式是在此目录下创建对应的文件类型文件夹,我很不喜欢,所以就都改在一个目录下了!)

  在 /editor/filemanager/connectors/aspx/config.ascx文件中修改SetConfig()方法,改后的代码如下:

 

        TypeConfig[ "File" ].AllowedExtensions            = new string[] { "7z""aiff""asf""avi""bmp""csv""doc""fla""flv""gif""gz""gzip""jpeg""jpg""mid""mov""mp3""mp4""mpc""mpeg""mpg""ods""odt""pdf""png""ppt""pxd""qt""ram""rar""rm""rmi""rmvb""rtf""sdc""sitd""swf""sxc""sxw""tar""tgz""tif""tiff""txt""vsd""wav""wma""wmv""xls""xml""zip" };
        TypeConfig[ 
"File" ].DeniedExtensions            = new string[] { };
        TypeConfig[ 
"File" ].FilesPath                    = "%UserFilesPath%file/" + DateTime.Now.ToString("yyyy-MM"+ "/";
        TypeConfig[ 
"File" ].FilesAbsolutePath            = ( UserFilesAbsolutePath == "" ? "" : "%UserFilesAbsolutePath%file/" + DateTime.Now.ToString("yyyy-MM"+ "/" );
        TypeConfig[ 
"File" ].QuickUploadPath            = "%UserFilesPath%file/" + DateTime.Now.ToString("yyyy-MM"+ "/";
        TypeConfig[ 
"File" ].QuickUploadAbsolutePath    = ( UserFilesAbsolutePath == "" ? "" : "%UserFilesAbsolutePath%file/" + DateTime.Now.ToString("yyyy-MM"+ "/" );

        TypeConfig[ 
"Image" ].AllowedExtensions            = new string[] { "bmp""gif""jpeg""jpg""png" };
        TypeConfig[ 
"Image" ].DeniedExtensions            = new string[] { };
        TypeConfig[ 
"Image" ].FilesPath                    = "%UserFilesPath%image/" + DateTime.Now.ToString("yyyy-MM"+ "/";
        TypeConfig[ 
"Image" ].FilesAbsolutePath            = ( UserFilesAbsolutePath == "" ? "" : "%UserFilesAbsolutePath%image/" + DateTime.Now.ToString("yyyy-MM"+ "/" );
        TypeConfig[ 
"Image" ].QuickUploadPath            = "%UserFilesPath%image/" + DateTime.Now.ToString("yyyy-MM"+ "/";
        TypeConfig[ 
"Image" ].QuickUploadAbsolutePath    = ( UserFilesAbsolutePath == "" ? "" : "%UserFilesAbsolutePath%image/"  + DateTime.Now.ToString("yyyy-MM"+ "/");

        TypeConfig[ 
"Flash" ].AllowedExtensions            = new string[] { "swf""flv" };
        TypeConfig[ 
"Flash" ].DeniedExtensions            = new string[] { };
        TypeConfig[ 
"Flash" ].FilesPath                    = "%UserFilesPath%flash/" + DateTime.Now.ToString("yyyy-MM"+ "/";
        TypeConfig[ 
"Flash" ].FilesAbsolutePath            = ( UserFilesAbsolutePath == "" ? "" : "%UserFilesAbsolutePath%flash/" + DateTime.Now.ToString("yyyy-MM"+ "/" );
        TypeConfig[ 
"Flash" ].QuickUploadPath            = "%UserFilesPath%flash/" + DateTime.Now.ToString("yyyy-MM"+ "/";
        TypeConfig[ 
"Flash" ].QuickUploadAbsolutePath    = ( UserFilesAbsolutePath == "" ? "" : "%UserFilesAbsolutePath%flash/" + DateTime.Now.ToString("yyyy-MM"+ "/" );

        TypeConfig[ 
"Media" ].AllowedExtensions            = new string[] { "aiff""asf""avi""bmp""fla""flv""gif""jpeg""jpg""mid""mov""mp3""mp4""mpc""mpeg""mpg""png""qt""ram""rm""rmi""rmvb""swf""tif""tiff""wav""wma""wmv" };
        TypeConfig[ 
"Media" ].DeniedExtensions            = new string[] { };
        TypeConfig[ 
"Media" ].FilesPath                    = "%UserFilesPath%media/" + DateTime.Now.ToString("yyyy-MM"+ "/";
        TypeConfig[ 
"Media" ].FilesAbsolutePath            = ( UserFilesAbsolutePath == "" ? "" : "%UserFilesAbsolutePath%media/" + DateTime.Now.ToString("yyyy-MM"+ "/" );
        TypeConfig[ 
"Media" ].QuickUploadPath            = "%UserFilesPath%media/" + DateTime.Now.ToString("yyyy-MM"+ "/";
        TypeConfig[ 
"Media" ].QuickUploadAbsolutePath    = ( UserFilesAbsolutePath == "" ? "" : "%UserFilesAbsolutePath%media/" + DateTime.Now.ToString("yyyy-MM"+ "/" );

 

效果我就不发了,肯定行。

 

四、上传所有东西重命名

 

 FCKeditor 的文件上传默认是不改名的,本地的文件名是什么,上传后保留原来的文件名;如果存在同名文件,则会被自动在文件名后面加 (n) 来标识。

FCKeditor For ASP.NET 的上传部分被编译到 DLL 文件里面了,所以只能通过修改源代码,再重新编译后方能使用。

使用:FCKeditor.Net_2.6.3.zip,asp.net 2.0版

找到项目中的FileBrowser/FileWorkerBase.cs

 

 

FCKeditor 上传自动重命名、按月创建文件夹和基本操作 [转]            while ( true )
            }

 

 

修改后的代码变成:

 

 

FCKeditor 上传自动重命名、按月创建文件夹和基本操作 [转]                while (true)
                }

 

 

重新生成解决方案。在网站项目中删除旧的FredCK.FCKeditorV2.dll,再添加新的引用,就OK了。

 

四、上传图片带水印

 

在看代码之前先简单的介绍一下我的想法。我在自己的网站中建立了H2Blog.config文件,用于存放网站的一些配置信息,如水印的类型(文字型,图片型),是否需要加水印,文字型水印的文字内容等等和本文无关的重要配置信息。所以在如下带代码中,有一段是用来读取这些配置信息的。
在FileUpload方法中找到oFile.SaveAs( sFilePath );语句。在其后加入

 

 

FCKeditor 上传自动重命名、按月创建文件夹和基本操作 [转]                    try
                    }

相关文章:

  • 2021-11-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-13
  • 2022-12-23
  • 2021-08-03
猜你喜欢
  • 2021-11-01
  • 2021-12-20
  • 2022-01-21
  • 2021-06-14
  • 2021-07-01
  • 2022-02-27
  • 2022-12-23
相关资源
相似解决方案