java fckeditor 文件上传

fckeditor-java 案例  by xuchengdongxcd@126.com



1.文件上传绝对路径配置
修改fckeditor.properties
connector.impl = net.fckeditor.connector.impl.LocalConnector
connector.userActionImpl=net.fckeditor.requestcycle.impl.EnabledUserAction
connector.userPathBuilderImpl = net.fckeditor.requestcycle.impl.ServerRootPathBuilder
localization.localeResolverImpl = net.fckeditor.localization.impl.AcceptLanguageHeaderResolver
connector.userFilesPath =http\://localhost\:8080/userfiles
connector.userFilesAbsolutePath =e\:/userfiles


修改$CATALINA_HOME/conf/server.xml
添加虚拟目录
<Context path="/userfiles" docBase="E:\userfiles" reloadable="true" debug="0"/>




2.文件上传按上传日期保存
修改net.fckeditor.connector.impl.AbstractLocalFileSystemConnector
覆盖java-core-2.6.jar里面的net.fckeditor.connector.impl.AbstractLocalFileSystemConnector


public String fileUpload(final ResourceType type,
final String currentFolder, final String fileName,
final InputStream inputStream)
throws InvalidCurrentFolderException, WriteException {
String absolutePath = getRealUserFilesAbsolutePath(RequestCycleHandler
.getUserFilesAbsolutePath(ThreadLocalData.getRequest()));
File typeDir = getOrCreateResourceTypeDir(absolutePath, type);
File currentDir = new File(typeDir, currentFolder);
if (!currentDir.exists() || !currentDir.isDirectory())
throw new InvalidCurrentFolderException();


/************** by xuchengdongxcd@126.com start **************/
SimpleDateFormat sFormat = new SimpleDateFormat("yyyyMMdd");
String date = sFormat.format(new Date());
currentDir = new File(currentDir, date);
if (!currentDir.exists() || !currentDir.isDirectory()) {
currentDir.mkdirs();
}
/************** by xuchengdongxcd@126.com end **************/


File newFile = new File(currentDir, fileName);
File fileToSave = UtilsFile.getUniqueFile(newFile.getAbsoluteFile());


try {
IOUtils.copyLarge(inputStream, new FileOutputStream(fileToSave));
} catch (IOException e) {
throw new WriteException();
}
return fileToSave.getName();
}






3.浏览上传图片文件和flash文件添加预览功能
修改/fckeditor/editor/filemanager/browser/default/frmresourceslist.html




oListManager.GetFileRowHtml = function( fileName, fileUrl, fileSize )
{
var fileUrl = ProtectPath( fileUrl );
// Build the link to view the folder.
var sLink = '<a href="#" οnclick="OpenFile(\'' + fileUrl + '\');return false;">' ;


// Get the file icon.
var sIcon = oIcons.GetIcon( fileName ) ;


/* return '<tr>' +
'<td width="16">' +
sLink +
'<img alt="" src="images/icons/' + sIcon + '.gif" width="16" height="16" border="0"><\/a>' +
'<\/td><td>&nbsp;' +
sLink +
fileName +
'<\/a>' +
'<\/td><td align="right" nowrap>&nbsp;' +
fileSize +
' KB' +
'<\/td><\/tr>' ;*/

/** by xuchengdong@126.com 2012.09.06 **/

var pattern = /(\.jpg$)|(\.gif$)|(\.png$)|(\.bmp$)/i;;

var rhtml = '<tr>' +
'<td width="16">' +
sLink +
'<img alt="" src="images/icons/' + sIcon + '.gif" width="16" height="16" border="0"/>' +
'<\/td><td>&nbsp;' +
sLink +
fileName +
'<\/a>' +
'<\/td>';

/** 添加预览功能 **/
if(pattern.test(fileUrl)){
rhtml += '<td><img  src="' + fileUrl + '" width="160" height="160" border="0"><\/a></td>';
}

pattern = /(\.swf$)/i;
if(pattern.test(fileUrl)){
rhtml += '<td><embed  src="' + fileUrl + '" width="160" height="160" border="0" type="application/x-shockwave-flash" play="true" loop="true" menu="true"/></td>';
}

rhtml+= '<td align="right" nowrap>&nbsp;' +
fileSize +
' KB' +
'<\/td><\/tr>' ;
return rhtml;
}


下载地址:http://download.csdn.net/download/qinglizoudangqi/4555200


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值