本文原创转载请注明
在开发用户管理功能时通常遇到这样一种情况:不同用户上传的图片等文件需要彼此隔离,也就是说每个用户在服务器上需要有一个单独的文件夹用于文件或图片存储。
目前用的最多的html编辑器要属FCKeditor。下面以.net版本为例,我介绍一下如何实现以上功能。
我使用的FCKeditor服务器版本为FCKeditor.Net_2.6.3 客户端版本为FCKeditor_2.6.4.1。FCKeditor的配置非常简单请参考 http://www.cnblogs.com/AlexCheng/archive/2009/08/18/1548701.html
第一步配置web.config文件在<appSettings></appSettings>之间加入
<!--FCKedit配置-->
<!--是否开启多用户支持-->
<add key="FCKeditor:MultiUser" value="true"/>
<add key="FCKeditor:BasePath" value="/webuser/fckeditor/"/>
<!--多用户存储路径:/webuser/userfiles/+Session["uid"].ToString()+"/"-->
<add key="FCKeditor:MultiUserPath" value="/webuser/userfiles/"/>
<!--Session["uid"]过期或未设置-->
<add key="FCKeditor:UserFilesPath" value="/webuser/userfiles/temp/"/>
找到FCKeditor客户端/fckeditor/editor/filemanager/connectors/aspx/config.ascx 打开找到SetConfig()
{
// SECURITY: You must explicitly enable this "connector". (Set it to "true").
Enabled = CheckAuthentication();
if (System.Configuration.ConfigurationSettings.AppSettings["FCKeditor:MultiUser"] == "true")
{
if (HttpContext.Current.Session["uid"]!=null)
{
UserFilesPath = System.Configuration.ConfigurationSettings.AppSettings["FCKeditor:MultiUserPath"] + HttpContext.Current.Session["uid"] + "/";
Session["FCKeditor:UserFilesPath"] = UserFilesPath;
}
else
{
UserFilesPath = System.Configuration.ConfigurationSettings.AppSettings["FCKeditor:UserFilesPath"];
Session["FCKeditor:UserFilesPath"] = UserFilesPath;
}
}
else
{
UserFilesPath = "/Upload/";
}
// URL path to user files.
//UserFilesPath = "/Upload/";
// The connector tries to resolve the above UserFilesPath automatically.
// Use the following setting it you prefer to explicitely specify the
// absolute path. Examples: 'C:\\MySite\\userfiles\\' or '/root/mysite/userfiles/'.
// Attention: The above 'UserFilesPath' URL must point to the same directory.
UserFilesAbsolutePath = "";
// Due to security issues with Apache modules, it is recommended to leave the
// following setting enabled.
ForceSingleExtension = true;
// Allowed Resource Types
AllowedTypes = new string[] { "File", "Image", "Flash", "Media" };
// For security, HTML is allowed in the first Kb of data for files having the
// following extensions only.
HtmlExtensions = new string[] { "html", "htm", "xml", "xsd", "txt", "js" };
TypeConfig[ "File" ].AllowedExtensions = new string[] { "7z", "aiff", "asf", "avi", "bmp", "csv", "doc", "fla", "flv", "gif", "gz", "gzip", "jpeg", "jpg", "mid", "mov", "mp3", "mp4", "mpc", "mpeg", "mpg", "ods", "odt", "pdf", "png", "ppt", "pxd", "qt", "ram", "rar", "rm", "rmi", "rmvb", "rtf", "sdc", "sitd", "swf", "sxc", "sxw", "tar", "tgz", "tif", "tiff", "txt", "vsd", "wav", "wma", "wmv", "xls", "xml", "zip" };
TypeConfig[ "File" ].DeniedExtensions = new string[] { };
TypeConfig[ "File" ].FilesPath = "%UserFilesPath%file/";
TypeConfig[ "File" ].FilesAbsolutePath = ( UserFilesAbsolutePath == "" ? "" : "%UserFilesAbsolutePath%file/" );
TypeConfig[ "File" ].QuickUploadPath = "%UserFilesPath%";
TypeConfig[ "File" ].QuickUploadAbsolutePath = ( UserFilesAbsolutePath == "" ? "" : "%UserFilesAbsolutePath%" );
TypeConfig[ "Image" ].AllowedExtensions = new string[] { "bmp", "gif", "jpeg", "jpg", "png" };
TypeConfig[ "Image" ].DeniedExtensions = new string[] { };
TypeConfig[ "Image" ].FilesPath = "%UserFilesPath%image/";
TypeConfig[ "Image" ].FilesAbsolutePath = ( UserFilesAbsolutePath == "" ? "" : "%UserFilesAbsolutePath%image/" );
TypeConfig[ "Image" ].QuickUploadPath = "%UserFilesPath%";
TypeConfig[ "Image" ].QuickUploadAbsolutePath = ( UserFilesAbsolutePath == "" ? "" : "%UserFilesAbsolutePath%" );
TypeConfig[ "Flash" ].AllowedExtensions = new string[] { "swf", "flv" };
TypeConfig[ "Flash" ].DeniedExtensions = new string[] { };
TypeConfig[ "Flash" ].FilesPath = "%UserFilesPath%flash/";
TypeConfig[ "Flash" ].FilesAbsolutePath = ( UserFilesAbsolutePath == "" ? "" : "%UserFilesAbsolutePath%flash/" );
TypeConfig[ "Flash" ].QuickUploadPath = "%UserFilesPath%";
TypeConfig[ "Flash" ].QuickUploadAbsolutePath = ( UserFilesAbsolutePath == "" ? "" : "%UserFilesAbsolutePath%" );
TypeConfig[ "Media" ].AllowedExtensions = new string[] { "aiff", "asf", "avi", "bmp", "fla", "flv", "gif", "jpeg", "jpg", "mid", "mov", "mp3", "mp4", "mpc", "mpeg", "mpg", "png", "qt", "ram", "rm", "rmi", "rmvb", "swf", "tif", "tiff", "wav", "wma", "wmv" };
TypeConfig[ "Media" ].DeniedExtensions = new string[] { };
TypeConfig[ "Media" ].FilesPath = "%UserFilesPath%media/";
TypeConfig[ "Media" ].FilesAbsolutePath = ( UserFilesAbsolutePath == "" ? "" : "%UserFilesAbsolutePath%media/" );
TypeConfig[ "Media" ].QuickUploadPath = "%UserFilesPath%";
TypeConfig[ "Media" ].QuickUploadAbsolutePath = ( UserFilesAbsolutePath == "" ? "" : "%UserFilesAbsolutePath%" );
}
第四步,在用户登录时给Session["uid"]赋值
这样遍可实现FCKeditor多用户功能。