单独使用fckeditor的文件上传功能

来源:互联网 发布:mac中如何替换ppt模版 编辑:程序博客网 时间:2024/05/18 03:53

单独使用fckeditor的文件上传功能

原文地址:http://blog.csdn.net/vkqiang/article/details/4027865

fckeditor的文件上传功能做的确实不错,但只能在编辑器中使用,有点不爽,今天做了一些修改,完成了对它的单独使用。

fckeditor版本:fckeditor2.6.4
  • 1.在web.xml中增加如下内容
<servlet>  <servlet-name>FckConnector</servlet-name>  <servlet-class>   net.fckeditor.connector.ConnectorServlet  </servlet-class>  <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping>  <servlet-name>FckConnector</servlet-name>  <url-pattern>/fckeditor/editor/filemanager/browser/default/connectors/jsp/connector  </url-pattern> </servlet-mapping>

注意:不要把原来的去掉,如去掉编辑器中的文件上传将不能使用

  • 2.修改

fckeditor/editor/filemanager/broswer/default/frmresourceslist.html文件

  • 添加一个函数用于获取参数
function GetUrlParam( paramName ){ var oRegex = new RegExp( '[/?&]' + paramName + '=([^&]+)', 'i' ) ; var oMatch = oRegex.exec( window.top.location.search ) ; if ( oMatch && oMatch.length > 1 )  return decodeURIComponent( oMatch[1] ) ; else  return '' ;}
  • 修改一个函数
function OpenFile( fileUrl ){/* //注释掉的是原来的window.top.opener.SetUrl( encodeURI( fileUrl ).replace( '#', '%23' ) ) ; window.top.close() ; window.top.opener.focus() ;*/ var parent = window.top.opener; if(parent!=null){  parentDocument = parent.document;  try{   //获取id,用于决定把值放在那个文本框中      if(parentDocument.getElementById(GetUrlParam("id"))!=null){                      parentDocument.getElementById(GetUrlParam("id")).value=fileUrl;    }   var basePath=parentDocument.getElementById("basePath");   var img=parentDocument.getElementById("imgurl");      if(img != null && basePath !=null)   {     img.src=basePath.value+fileUrl;   }  }catch(e){   window.top.close();  }  window.top.close(); } if(window.top.opener!=null){  window.top.opener.SetUrl(  fileUrl  ) ;  window.top.close() ;  window.top.opener.focus() ; }else{   window.returnValue = fileUrl ;   window.top.close() ;  } }
  • 3.调用
window.open('/fckeditor/editor/filemanager/browser/default/browser.html?Type=Image&Connector=connectors/jsp/connector&id=selectLOGO','','width=600,height=400,left=200,top=200');

参数id是你想要把文件url放在那个文件框的id

0 0