一、首先工具的下载,找到相应的版本进行下载

    ckeditor_3.6.6.2+CKFinder2.0.2 http://ckeditor.com/download

    
打开war文件,然后将相关的jar文件复制到WEB-INF/lib下面即可,把ckeditor和ckfinder文件夹拷贝到web工程下,我是放到webapp/js路径下。当然可以去掉ckeditor里一些无关的文件.
说明:medsite为项目名称

二、配置文件

1、在web.xml中配置如下,增加ckeditor的启动

  1. <servlet>
  2. <servlet-name>ConnectorServlet</servlet-name>
  3. <servlet-class>com.ckfinder.connector.ConnectorServlet</servlet-class>
  4. <init-param>
  5. <param-name>XMLConfig</param-name>
  6. <param-value>/WEB-INF/ckfinder.xml</param-value>
  7. </init-param>
  8. <init-param>
  9. <param-name>debug</param-name>
  10. <param-value>false</param-value>
  11. </init-param>
  12. <load-on-startup>1</load-on-startup>
  13. </servlet>
  14. <servlet-mapping>
  15. <servlet-name>ConnectorServlet</servlet-name>
  16. <url-pattern>
  17. /js/ckfinder/core/connector/java/connector.java
  18. </url-pattern>
  19. </servlet-mapping>
  20. <filter>
  21. <filter-name>FileUploadFilter</filter-name>
  22. <filter-class>com.ckfinder.connector.FileUploadFilter</filter-class>
  23. <init-param>
  24. <param-name>sessionCookieName</param-name>
  25. <param-value>JSESSIONID</param-value>
  26. </init-param>
  27. <init-param>
  28. <param-name>sessionParameterName</param-name>
  29. <param-value>jsessionid</param-value>
  30. </init-param>
  31. </filter>
  32. <filter-mapping>
  33. <filter-name>FileUploadFilter</filter-name>
  34. <url-pattern>
  35. /js/ckfinder/core/connector/java/connector.java
  36. </url-pattern>
  37. </filter-mapping>

2、在web.xml文件统计目录下新建ckfinder.xml,保存

  1. <config>
  2. <enabled>true</enabled>
  3. <baseDir></baseDir> //这里不要添加任何目录
  4. <baseURL>/medsite/upload/</baseURL> //这里指定上传的文                           件夹,medsite为项目名称
  5. <licenseKey></licenseKey>
  6. <licenseName></licenseName>
  7. <imgWidth>1600</imgWidth>
  8. <imgHeight>1200</imgHeight>
  9. <imgQuality>80</imgQuality>
  10. <uriEncoding>UTF-8</uriEncoding>
  11. <forceASCII>false</forceASCII>
  12. <userRoleSessionVar>CKFinder_UserRole</userRoleSessionVar>
  13. <checkDoubleExtension>true</checkDoubleExtension>
  14. <checkSizeAfterScaling>true</checkSizeAfterScaling>
  15. <secureImageUploads>true</secureImageUploads>
  16. <htmlExtensions>html,htm,xml,js</htmlExtensions>
  17. <hideFolders>
  18. <folder>.svn</folder>
  19. <folder>CVS</folder>
  20. </hideFolders>
  21. <hideFiles>
  22. <file>.*</file>
  23. </hideFiles>
  24. <defaultResourceTypes></defaultResourceTypes>
  25. <types>
  26. <type name="Files">
  27. <url>%BASE_URL%files/</url>
  28. <directory>%BASE_DIR%files</directory>
  29. <maxSize>0</maxSize>
  30. <allowedExtensions>7z,aiff,asf,avi,bmp,csv,doc,docx,fla,flv,gif,gz,gzip,jpeg,jpg,mid,mov,mp3,mp4,mpc,mpeg,mpg,ods,odt,pdf,png,ppt,pptx,pxd,qt,ram,rar,rm,rmi,rmvb,rtf,sdc,sitd,swf,sxc,sxw,tar,tgz,tif,tiff,txt,vsd,wav,wma,wmv,xls,xlsx,zip
  31. </allowedExtensions>
  32. <deniedExtensions></deniedExtensions>
  33. </type>
  34. <type name="Images">
  35. <url>%BASE_URL%images/</url>
  36. <directory>%BASE_DIR%images</directory>
  37. <maxSize>0</maxSize>
  38. <allowedExtensions>bmp,gif,jpeg,jpg,png</allowedExtensions>
  39. <deniedExtensions></deniedExtensions>
  40. </type>
  41. <type name="Flash">
  42. <url>%BASE_URL%flash/</url>
  43. <directory>%BASE_DIR%flash</directory>
  44. <maxSize>0</maxSize>
  45. <allowedExtensions>swf,flv</allowedExtensions>
  46. <deniedExtensions></deniedExtensions>
  47. </type>
  48. </types>
  49. <accessControls>
  50. <accessControl>
  51. <role>*</role>
  52. <resourceType>*</resourceType>
  53. <folder>/</folder>
  54. <folderView>true</folderView>
  55. <folderCreate>true</folderCreate>
  56. <folderRename>true</folderRename>
  57. <folderDelete>true</folderDelete>
  58. <fileView>true</fileView>
  59. <fileUpload>true</fileUpload>
  60. <fileRename>true</fileRename>
  61. <fileDelete>true</fileDelete>
  62. </accessControl>
  63. </accessControls>
  64. <thumbs>
  65. <enabled>true</enabled>
  66. <url>%BASE_URL%_thumbs/</url>
  67. <directory>%BASE_DIR%_thumbs</directory>
  68. <directAccess>false</directAccess>
  69. <maxHeight>100</maxHeight>
  70. <maxWidth>100</maxWidth>
  71. <quality>80</quality>
  72. </thumbs>
  73. <plugins>
  74. <plugin>
  75. <name>imageresize</name>
  76. <class>com.ckfinder.connector.plugins.ImageResize</class>
  77. <params>
  78. <param name="smallThumb" value="90x90"></param>
  79. <param name="mediumThumb" value="120x120"></param>
  80. <param name="largeThumb" value="180x180"></param>
  81. </params>
  82. </plugin>
  83. <plugin>
  84. <name>fileeditor</name>
  85. <class>com.ckfinder.connector.plugins.FileEditor</class>
  86. <params></params>
  87. </plugin>
  88. </plugins>
  89. <basePathBuilderImpl>com.ckfinder.connector.configuration.ConfigurationPathBuilder</basePathBuilderImpl>
  90. </config>

3、配置ckeditor,可供ckfinder上传图片和文件

  1. /*
  2. Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
  3. For licensing, see LICENSE.html or http://ckeditor.com/license
  4. */
  5. CKEDITOR.editorConfig = function( config )
  6. {
  7. //配置CKFinder
  8. config.filebrowserBrowseUrl ='js/ckfinder/ckfinder.html';
  9. config.filebrowserImageBrowseUrl ='js/ckfinder/ckfinder.html?Type=Images';
  10. config.filebrowserFlashBrowseUrl = 'js/ckfinder/ckfinder.html?Type=Flash';
  11. config.filebrowserUploadUrl = 'js/ckfinder/core/connector/java/connector.java?command=QuickUpload&type=Files';
  12. config.filebrowserImageUploadUrl = 'js/ckfinder/core/connector/java/connector.java?command=QuickUpload&type=Images';
  13. config.filebrowserFlashUploadUrl = 'js/ckfinder/core/connector/java/connector.java?command=QuickUpload&type=Flash';
  14. config.filebrowserWindowHeight='50%';//CKFinder浏览窗口高度,默认值70%
  15. config.filebrowserWindowWidth='70%';//CKFinder浏览窗口宽度,默认值80%
  16. };

4、拷贝此目录下的文件,复制到src下

 
如下所示
 

5、lib包给大家展示一下

 

6、效果展示

 
 
此时即可上传文件和图片了

7、修改上传文件的文件名称

 
修改此类下的validateUploadItem方法
  1. private boolean validateUploadItem(final FileItem item, final String path) {
  2. if (item.getName() != null && item.getName().length() > 0) {
  3. this.fileName = getFileItemName(item);
  4. } else {
  5. this.errorCode = Constants.Errors.CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID;
  6. return false;
  7. }
  8. //this.newFileName = this.fileName;
  9. String sExtentsion = FileUtils.getFileExtension(this.fileName);
  10. SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
  11. this.newFileName = format.format(new Date()) + "." + sExtentsion;
  12. String unsafeFileName = this.newFileName;
  13. for (char c : UNSAFE_FILE_NAME_CHARS) {
  14. this.newFileName = unsafeFileName.replace(c, '_');
  15. }
  16. if (configuration.forceASCII()) {
  17. this.newFileName = FileUtils.convertToASCII(this.newFileName);
  18. }
  19. if (!unsafeFileName.equals(this.newFileName)) {
  20. this.errorCode =
  21. Constants.Errors.CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID_NAME_RENAMED;
  22. }
  23. if (FileUtils.checkIfDirIsHidden(this.currentFolder, configuration)) {
  24. this.errorCode = Constants.Errors.CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST;
  25. return false;
  26. }
  27. if (!FileUtils.checkFileName(this.newFileName)
  28. || FileUtils.checkIfFileIsHidden(this.newFileName,
  29. configuration)) {
  30. this.errorCode = Constants.Errors.CKFINDER_CONNECTOR_ERROR_INVALID_NAME;
  31. return false;
  32. }
  33. int checkFileExt = FileUtils.checkFileExtension(this.newFileName,
  34. configuration
  35. .getTypes().get(type),
  36. configuration,
  37. true);
  38. if (checkFileExt == 1) {
  39. this.errorCode = Constants.Errors.CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION;
  40. return false;
  41. } else if (checkFileExt == 2) {
  42. this.newFileName = FileUtils.renameFileWithBadExt(this.newFileName);
  43. }
  44. try {
  45. File file = new File(path, getFinalFileName(path,
  46. this.newFileName));
  47. if (!FileUtils.checkFileSize(configuration.getTypes().get(this.type),
  48. item.getSize())
  49. && !(configuration.checkSizeAfterScaling() && ImageUtils
  50. .isImage(file))) {
  51. this.errorCode =
  52. Constants.Errors.CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG;
  53. return false;
  54. }
  55. if (configuration.getSecureImageUploads() && ImageUtils.isImage(file)
  56. && !ImageUtils.checkImageFile(item)) {
  57. this.errorCode =
  58. Constants.Errors.CKFINDER_CONNECTOR_ERROR_UPLOADED_CORRUPT;
  59. return false;
  60. }
  61. if (!FileUtils.checkIfFileIsHtmlFile(file.getName(), configuration)
  62. && FileUtils.detectHtml(item)) {
  63. this.errorCode =
  64. Constants.Errors.CKFINDER_CONNECTOR_ERROR_UPLOADED_WRONG_HTML_FILE;
  65. return false;
  66. }
  67. } catch (SecurityException e) {
  68. if (configuration.isDebugMode()) {
  69. this.exception = e;
  70. }
  71. this.errorCode = Constants.Errors.CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED;
  72. return false;
  73. } catch (IOException e) {
  74. if (configuration.isDebugMode()) {
  75. this.exception = e;
  76. }
  77. this.errorCode = Constants.Errors.CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED;
  78. return false;
  79. }
  80. return true;
  81. }
此时文件的名称就像上图展示的,以时间命名了



ckeditor_3.6.6.2+CKFinder2.0.2配置的更多相关文章

  1. CentOS 7.0安装配置Vsftp服务器

    一.配置防火墙,开启FTP服务器需要的端口 CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop fi ...

  2. Solr4.0 如何配置使用UUID自动生成id值

    原文链接http://blog.csdn.net/keepthinking_/article/details/8501058#comments 最近学习了Lucene,随便也学习了Solr,Solr规 ...

  3. 网站开启https后加密协议始终是TLS1.0如何配置成TLS1.2?

    p { margin-bottom: 0.1in; line-height: 120% } 网站开启https后加密协议始终是TLS1.0如何配置成TLS1.2? 要在服务器上开启 TLSv1.,通常 ...

  4. 驱动开发学习笔记. 0.01 配置arm-linux-gcc 交叉编译器

    驱动开发读书笔记. 0.01 配置arm-linux-gcc 交叉编译器 什么是gcc: 就像windows上的VS 工具,用来编译代码,具体请自己搜索相关资料 怎么用PC机的gcc 和 arm-li ...

  5. RHEL 7.0 本地配置yum源

    RHEL 7.0 本地配置yum源  yum简介  yum = Yellow dog Updater, Modified 主要功能是更方便的添加/删除/更新RPM包. 它能自动解决包的倚赖性问题. 它 ...

  6. JSP的那些事儿(2)---- DWR2.0 的配置和使用

    JSP的那些事儿(2)----DWR2.0 的配置和使用 分类: Web开发 JAVA 2009-04-23 15:43 999人阅读 评论(0) 收藏 举报 jspdwrjavascriptserv ...

  7. CentOS 7.0系统安装配置LAMP服务器(Apache+PHP+MariaDB)

    CentOS 7.0接触到的用户是比较少的,今天看了站长写了一篇关于centos7中安装配置LAMP服务器的教程,下面我把文章稍加整理一下转给大家学习交流,希望例子能给各位带来帮助哦.   cento ...

  8. CentOS 7.0安装配置LAMP服务器(Apache+PHP+MariaDB)

    CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop firewalld.service #停止fir ...

  9. Ubuntu14.10+cuda7.0+caffe配置

    转自:http://blog.csdn.net/lu597203933/article/details/46742199 Ubuntu14.10+cuda7.0+caffe配置 一:linux安装 L ...

随机推荐

  1. 自定义cell,根据数据源,要对cell的布局进行调整,没有实现调整的相应效果

    自定义cell,用于两种显示情况,首次进来A种情况(主材页面),正确显示,然后切换B种情况(辅材情况),可以正确显示,但是当再次切换回A种情况(主材情况)的时候,主材cell不能正常显示了,遗留的B中 ...

  2. 使用anyremote进行远程鼠标控制

    源代码安装 http://anyremote.sourceforge.net/pre.html 安装  -xtest apt-get install libxtst-dev 安装 glib sudo ...

  3. myeclipse 调试JSP页面

    http://jingyan.baidu.com/article/636f38bb1ef1aad6b9461048.html

  4. 查找List中的最大最小值

    以下实例演示了如何使用 Collections 类的 max() 和 min() 方法来获取List中最大最小值: import java.util.*; public class Main { pu ...

  5. jQuery实现父窗口的问题

    因为先前遇到的问题,所以我考虑采用 IFRAME 来隔离不同的脚本,从而实现我需要的效果. 在框架中,我用 JavaScript 获取 JSON 数据,组织成 HTML 代码,最后将其填充至上层文档的 ...

  6. 【转】VC6.0打开或者添加工程文件崩溃的解决方法

    很多学习编程的同学都遇到这样的问题,在Windows操作系统下使用Visual C++ 6.0编程时,如果点击菜单中的[打开]或者[添加],或者按快捷键,都会弹出下图的对话框,出现程序崩溃并退出的情况 ...

  7. Webkit之资源加载

    一.webkit资源分类 webkit中有多种资源,大致分为以下几种: HTML文本 CSS样式文本 - CachedCSSStyleSheet 字体 - CachedFont 图片 - Cached ...

  8. HTTP的学习

    一个完整的HTTP请求: 1 简历TCP连接 2 web浏览器像web服务器发送请求命令 3 web浏览器发送请求头信息 4 web服务器应答 5 web服务器发送应答头信息 6 web服务器像浏览器 ...

  9. linux的mount(挂载)NFS 共享,命令详解

    Linux下挂载(mount)光盘镜像文件.移动硬盘.U盘.Windows和NFS网络共享 linux是一个优秀的开放源码的操作系统,可以运行在大到巨型小到掌上型各类计算机系统上,随着 linux系统 ...

  10. Linux查看文件夹大小du

    du命令参数详解见: http://baike.baidu.com/view/43913.htm 下面我们只对其做简单介绍: 查看linux文件目录的大小和文件夹包含的文件数   统计总数大小   d ...