生活随笔
收集整理的這篇文章主要介紹了
ckeditor_3.6.6.2+CKFinder2.0.2配置
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、首先工具的下載,找到相應的版本進行下載
? ??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的啟動
<servlet> <servlet-name>ConnectorServlet</servlet-name> <servlet-class>com.ckfinder.connector.ConnectorServlet</servlet-class> <init-param> <param-name>XMLConfig</param-name> <param-value>/WEB-INF/ckfinder.xml</param-value> </init-param> <init-param> <param-name>debug</param-name> <param-value>false</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>ConnectorServlet</servlet-name> <url-pattern> /js/ckfinder/core/connector/java/connector.java </url-pattern> </servlet-mapping> <filter> <filter-name>FileUploadFilter</filter-name> <filter-class>com.ckfinder.connector.FileUploadFilter</filter-class> <init-param> <param-name>sessionCookieName</param-name> <param-value>JSESSIONID</param-value> </init-param> <init-param> <param-name>sessionParameterName</param-name> <param-value>jsessionid</param-value> </init-param> </filter> <filter-mapping> <filter-name>FileUploadFilter</filter-name> <url-pattern> /js/ckfinder/core/connector/java/connector.java </url-pattern> </filter-mapping>2、在web.xml文件統計目錄下新建ckfinder.xml,保存
<config> <enabled>true</enabled> <baseDir></baseDir> //這里不要添加任何目錄 <baseURL>/medsite/upload/</baseURL> //這里指定上傳的文???????????????????????????件夾,medsite為項目名稱 <licenseKey></licenseKey> <licenseName></licenseName> <imgWidth>1600</imgWidth> <imgHeight>1200</imgHeight> <imgQuality>80</imgQuality> <uriEncoding>UTF-8</uriEncoding> <forceASCII>false</forceASCII> <userRoleSessionVar>CKFinder_UserRole</userRoleSessionVar> <checkDoubleExtension>true</checkDoubleExtension> <checkSizeAfterScaling>true</checkSizeAfterScaling> <secureImageUploads>true</secureImageUploads> <htmlExtensions>html,htm,xml,js</htmlExtensions> <hideFolders> <folder>.svn</folder> <folder>CVS</folder> </hideFolders> <hideFiles> <file>.*</file> </hideFiles> <defaultResourceTypes></defaultResourceTypes> <types> <type name="Files"> <url>%BASE_URL%files/</url> <directory>%BASE_DIR%files</directory> <maxSize>0</maxSize> <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 </allowedExtensions> <deniedExtensions></deniedExtensions> </type> <type name="Images"> <url>%BASE_URL%images/</url> <directory>%BASE_DIR%images</directory> <maxSize>0</maxSize> <allowedExtensions>bmp,gif,jpeg,jpg,png</allowedExtensions> <deniedExtensions></deniedExtensions> </type> <type name="Flash"> <url>%BASE_URL%flash/</url> <directory>%BASE_DIR%flash</directory> <maxSize>0</maxSize> <allowedExtensions>swf,flv</allowedExtensions> <deniedExtensions></deniedExtensions> </type> </types> <accessControls> <accessControl> <role>*</role> <resourceType>*</resourceType> <folder>/</folder> <folderView>true</folderView> <folderCreate>true</folderCreate> <folderRename>true</folderRename> <folderDelete>true</folderDelete> <fileView>true</fileView> <fileUpload>true</fileUpload> <fileRename>true</fileRename> <fileDelete>true</fileDelete> </accessControl> </accessControls> <thumbs> <enabled>true</enabled> <url>%BASE_URL%_thumbs/</url> <directory>%BASE_DIR%_thumbs</directory> <directAccess>false</directAccess> <maxHeight>100</maxHeight> <maxWidth>100</maxWidth> <quality>80</quality> </thumbs> <plugins> <plugin> <name>imageresize</name> <class>com.ckfinder.connector.plugins.ImageResize</class> <params> <param name="smallThumb" value="90x90"></param> <param name="mediumThumb" value="120x120"></param> <param name="largeThumb" value="180x180"></param> </params> </plugin> <plugin> <name>fileeditor</name> <class>com.ckfinder.connector.plugins.FileEditor</class> <params></params> </plugin> </plugins> <basePathBuilderImpl>com.ckfinder.connector.configuration.ConfigurationPathBuilder</basePathBuilderImpl></config>3、配置ckeditor,可供ckfinder上傳圖片和文件
/*Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.For licensing, see LICENSE.html or http://ckeditor.com/license*/CKEDITOR.editorConfig = function( config ){ //配置CKFinder config.filebrowserBrowseUrl ='js/ckfinder/ckfinder.html'; config.filebrowserImageBrowseUrl ='js/ckfinder/ckfinder.html?Type=Images'; config.filebrowserFlashBrowseUrl = 'js/ckfinder/ckfinder.html?Type=Flash'; config.filebrowserUploadUrl = 'js/ckfinder/core/connector/java/connector.java?command=QuickUpload&type=Files'; config.filebrowserImageUploadUrl = 'js/ckfinder/core/connector/java/connector.java?command=QuickUpload&type=Images'; config.filebrowserFlashUploadUrl = 'js/ckfinder/core/connector/java/connector.java?command=QuickUpload&type=Flash'; config.filebrowserWindowHeight='50%';//CKFinder瀏覽窗口高度,默認值70% config.filebrowserWindowWidth='70%';//CKFinder瀏覽窗口寬度,默認值80%};4、拷貝此目錄下的文件,復制到src下
?
如下所示?
5、lib包給大家展示一下
?
6、效果展示
?
?
此時即可上傳文件和圖片了
7、修改上傳文件的文件名稱
?
修改此類下的
validateUploadItem方法private boolean validateUploadItem(final FileItem item, final String path) { if (item.getName() != null && item.getName().length() > 0) { this.fileName = getFileItemName(item); } else { this.errorCode = Constants.Errors.CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID; return false; } //this.newFileName = this.fileName; String sExtentsion = FileUtils.getFileExtension(this.fileName); SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss"); this.newFileName = format.format(new Date()) + "." + sExtentsion; String unsafeFileName = this.newFileName; for (char c : UNSAFE_FILE_NAME_CHARS) { this.newFileName = unsafeFileName.replace(c, '_'); } if (configuration.forceASCII()) { this.newFileName = FileUtils.convertToASCII(this.newFileName); } if (!unsafeFileName.equals(this.newFileName)) { this.errorCode = Constants.Errors.CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID_NAME_RENAMED; } if (FileUtils.checkIfDirIsHidden(this.currentFolder, configuration)) { this.errorCode = Constants.Errors.CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST; return false; } if (!FileUtils.checkFileName(this.newFileName) || FileUtils.checkIfFileIsHidden(this.newFileName, configuration)) { this.errorCode = Constants.Errors.CKFINDER_CONNECTOR_ERROR_INVALID_NAME; return false; } int checkFileExt = FileUtils.checkFileExtension(this.newFileName, configuration .getTypes().get(type), configuration, true); if (checkFileExt == 1) { this.errorCode = Constants.Errors.CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION; return false; } else if (checkFileExt == 2) { this.newFileName = FileUtils.renameFileWithBadExt(this.newFileName); } try { File file = new File(path, getFinalFileName(path, this.newFileName)); if (!FileUtils.checkFileSize(configuration.getTypes().get(this.type), item.getSize()) && !(configuration.checkSizeAfterScaling() && ImageUtils .isImage(file))) { this.errorCode = Constants.Errors.CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG; return false; } if (configuration.getSecureImageUploads() && ImageUtils.isImage(file) && !ImageUtils.checkImageFile(item)) { this.errorCode = Constants.Errors.CKFINDER_CONNECTOR_ERROR_UPLOADED_CORRUPT; return false; } if (!FileUtils.checkIfFileIsHtmlFile(file.getName(), configuration) && FileUtils.detectHtml(item)) { this.errorCode = Constants.Errors.CKFINDER_CONNECTOR_ERROR_UPLOADED_WRONG_HTML_FILE; return false; } } catch (SecurityException e) { if (configuration.isDebugMode()) { this.exception = e; } this.errorCode = Constants.Errors.CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; return false; } catch (IOException e) { if (configuration.isDebugMode()) { this.exception = e; } this.errorCode = Constants.Errors.CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED; return false; } return true; }此時文件的名稱就像上圖展示的,以時間命名了
來自為知筆記(Wiz)
總結
以上是生活随笔為你收集整理的ckeditor_3.6.6.2+CKFinder2.0.2配置的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。