FCK(默认)一直以来,用户都可以共享所上传的图片,多多少少都会有点问题,而且在很多情况下也不能满足需求,但其实FCK也想到了这点,他自己本生就提供了接口,可以每个用户指定文件夹,让用户上传的图片,不用进行共享
第一步:实现接口ContextPathBuilder
如果只是多用户无法共享图片的功能,实现getUserFilesPath方法就可以了,只用返回时,返回服务器相对路径就可
第二步:配置实现类
在fckeditor.properties文件中加入下面这设置就可以了
connector.userActionImpl=net.fckeditor.requestcycle.impl.EnabledUserAction
connector.userPathBuilderImpl=com.semcolon.action.UserPathBuilderImpl
connector.userFilesPath =/userfiles
第一步:实现接口ContextPathBuilder
import javax.servlet.http.HttpServletRequest;
import net.fckeditor.handlers.PropertiesLoader;
import net.fckeditor.requestcycle.UserPathBuilder;
import com.clubgold.btg.sft.bean.Merchant;
public class UserPathBuilderImpl implements UserPathBuilder {
// 虚拟目录设置
public String getUserFilesAbsolutePath(HttpServletRequest request) {
StringBuffer userFilesPathBuffer = new StringBuffer();
// 获得定义connector.userFilesAbsolutePath的值
String path = PropertiesLoader.getProperty("connector.userFilesAbsolutePath");
userFilesPathBuffer.append(path);
userFilesPathBuffer.append(System.getProperty("file.separator"));
Merchant merchant = (Merchant) request.getSession().getAttribute("merchant");
String userPath = "userDefault";
if (merchant != null) {
userPath = String.valueOf(merchant.getId());
}
userFilesPathBuffer.append(userPath);
return userFilesPathBuffer.toString();
}
// FCK目录设置
public String getUserFilesPath(HttpServletRequest request) {
StringBuffer userFilesPathBuffer = new StringBuffer();
// 获得定义connector.userFilesPath的值
String path = PropertiesLoader.getProperty("connector.userFilesPath");
userFilesPathBuffer.append(path);
userFilesPathBuffer.append("/");
Merchant merchant = (Merchant) request.getSession().getAttribute("merchant");
String userPath = "userDefault";
if (merchant != null) {
userPath = String.valueOf(merchant.getId());
}
userFilesPathBuffer.append(userPath);
return userFilesPathBuffer.toString();
}
}
如果只是多用户无法共享图片的功能,实现getUserFilesPath方法就可以了,只用返回时,返回服务器相对路径就可
第二步:配置实现类
在fckeditor.properties文件中加入下面这设置就可以了
connector.userActionImpl=net.fckeditor.requestcycle.impl.EnabledUserAction
connector.userPathBuilderImpl=com.semcolon.action.UserPathBuilderImpl
connector.userFilesPath =/userfiles