王朝网络
分享
 
 
 

实现FCKeditor 多用户分文件夹上传图片等附件

王朝other·作者佚名  2008-12-13
宽屏版  字体: |||超大  

FCKeditor在web.config中有多项设置:view plaincopy to clipboardprint?

<appSettings>

<!--FCKeditor设置(主要是以下两项)-->

<!--FCKeditor编辑器路径-->

<add key="FCKeditor:BasePath" value="/FCKeditor/"/>

<!--FCKeditor用户附件上传路径-->

<add key="FCKeditor:UserFilesPath" value="/Resources/TempUpload/"/>

</appSettings>

<appSettings>

<!--FCKeditor设置(主要是以下两项)-->

<!--FCKeditor编辑器路径-->

<add key="FCKeditor:BasePath" value="/FCKeditor/"/>

<!--FCKeditor用户附件上传路径-->

<add key="FCKeditor:UserFilesPath" value="/Resources/TempUpload/"/>

</appSettings>用户登录后通过FCKeditor上传文件则要放置在用户共用上传路径“/Resources/UserUpload/”+“用户邮箱地址”,如“/Resources/UserUpload/user@gmail.com”。FCKeditor.net获取上传路径文件是:FileWorkerBase.cs,打开找到以下部分view plaincopy to clipboardprint?

protected string UserFilesPath

{

get

{

if ( sUserFilesPath == null )

{

// 第一回从Application["FCKeditor:UserFilesPath"] 中读取,如果没有尝试其它方式

sUserFilesPath = (string)Application["FCKeditor:UserFilesPath"] ;

// 第二回从Session["FCKeditor:UserFilesPath"] 中读取,如果没有尝试其它方式

if ( sUserFilesPath == null || sUserFilesPath.Length == 0 )

{

sUserFilesPath = (string)Session["FCKeditor:UserFilesPath"] ;

// 第三回从web.config中读取,如果没有尝试其它方式

if ( sUserFilesPath == null || sUserFilesPath.Length == 0 )

{

sUserFilesPath = System.Configuration.ConfigurationSettings.AppSettings["FCKeditor:UserFilesPath"] ;

// 第四回从DEFAULT_USER_FILES_PATH(这个变量在同文件中)中读取,如果没有尝试其它方式

if ( sUserFilesPath == null || sUserFilesPath.Length == 0 )

sUserFilesPath = DEFAULT_USER_FILES_PATH ;

// 第五回从网址参数ServerPath中读取

if ( sUserFilesPath == null || sUserFilesPath.Length == 0 )

{

sUserFilesPath = Request.QueryString["ServerPath"] ;

}

}

}

// Check that the user path ends with slash ("/")

if ( ! sUserFilesPath.EndsWith("/") )

sUserFilesPath += "/" ;

}

return sUserFilesPath ;

}

}

protected string UserFilesPath

{

get

{

if ( sUserFilesPath == null )

{

// 第一回从Application["FCKeditor:UserFilesPath"] 中读取,如果没有尝试其它方式

sUserFilesPath = (string)Application["FCKeditor:UserFilesPath"] ;

// 第二回从Session["FCKeditor:UserFilesPath"] 中读取,如果没有尝试其它方式

if ( sUserFilesPath == null || sUserFilesPath.Length == 0 )

{

sUserFilesPath = (string)Session["FCKeditor:UserFilesPath"] ;

// 第三回从web.config中读取,如果没有尝试其它方式

if ( sUserFilesPath == null || sUserFilesPath.Length == 0 )

{

sUserFilesPath = System.Configuration.ConfigurationSettings.AppSettings["FCKeditor:UserFilesPath"] ;

// 第四回从DEFAULT_USER_FILES_PATH(这个变量在同文件中)中读取,如果没有尝试其它方式

if ( sUserFilesPath == null || sUserFilesPath.Length == 0 )

sUserFilesPath = DEFAULT_USER_FILES_PATH ;

// 第五回从网址参数ServerPath中读取

if ( sUserFilesPath == null || sUserFilesPath.Length == 0 )

{

sUserFilesPath = Request.QueryString["ServerPath"] ;

}

}

}

// Check that the user path ends with slash ("/")

if ( ! sUserFilesPath.EndsWith("/") )

sUserFilesPath += "/" ;

}

return sUserFilesPath ;

}

}从上面的注释可以看到用户上传路径的顺序,只要在页面加载的时候设置下Session["FCKeditor:UserFilesPath"]就可以设置FCKeditor上用户上传路径了view plaincopy to clipboardprint?

protected void Page_Load(object sender, EventArgs e)

{

if (!Page.IsPostBack)

Session["FCKeditor:UserFilesPath"] = "用户上传路径";

}

protected void Page_Load(object sender, EventArgs e)

{

if (!Page.IsPostBack)

Session["FCKeditor:UserFilesPath"] = "用户上传路径";

}(我在配置的时候关闭了文件浏览,只提供文件快速上传)但是在使用的时候如果“Resources/UserUpload/user@gmail.com”中的user@gmail.com路径没创建,上传中FCKeditor它不会创建,也导致了文件无法上传成功,那就需要再修改FCKeditor.net项目中的Uploader.cs文件,添加一段文件夹存在的检测代码,如果不存在用户指定的文件夹侧创建一个view plaincopy to clipboardprint?

// Get the uploaded file name.

string sFileName = System.IO.Path.GetFileName( oFile.FileName ) ;

int iCounter = 0 ;

//景裔添加

//检查上传目录是否已经被创建

//开始==========================================

//检查当前完整路径是否存在,不存在则开始逐级轮询检查,不存则就创建

if (!System.IO.Directory.Exists(UserFilesDirectory))

{

string[] tempDirectorys = UserFilesDirectory.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries);

string tempDirectory = string.Empty;

for (int i = 0; i < tempDirectorys.Length; i++)

{

tempDirectory += tempDirectorys[i] + "\\";

if (!System.IO.Directory.Exists(tempDirectory))

System.IO.Directory.CreateDirectory(tempDirectory);

}

}

//结束==========================================

while ( true )

{

string sFilePath = System.IO.Path.Combine( this.UserFilesDirectory, sFileName ) ;

if ( System.IO.File.Exists( sFilePath ) )

{

iCounter++ ;

sFileName =

System.IO.Path.GetFileNameWithoutExtension( oFile.FileName ) +

"(" + iCounter + ")" +

System.IO.Path.GetExtension( oFile.FileName ) ;

iErrorNumber = 201 ;

}

else

{

oFile.SaveAs( sFilePath ) ;

sFileUrl = this.UserFilesPath + sFileName ;

break ;

}

}

// Get the uploaded file name.

string sFileName = System.IO.Path.GetFileName( oFile.FileName ) ;

int iCounter = 0 ;

//景裔添加

//检查上传目录是否已经被创建

//开始==========================================

//检查当前完整路径是否存在,不存在则开始逐级轮询检查,不存则就创建

if (!System.IO.Directory.Exists(UserFilesDirectory))

{

string[] tempDirectorys = UserFilesDirectory.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries);

string tempDirectory = string.Empty;

for (int i = 0; i < tempDirectorys.Length; i++)

{

tempDirectory += tempDirectorys[i] + "\\";

if (!System.IO.Directory.Exists(tempDirectory))

System.IO.Directory.CreateDirectory(tempDirectory);

}

}

//结束==========================================

while ( true )

{

string sFilePath = System.IO.Path.Combine( this.UserFilesDirectory, sFileName ) ;

if ( System.IO.File.Exists( sFilePath ) )

{

iCounter++ ;

sFileName =

System.IO.Path.GetFileNameWithoutExtension( oFile.FileName ) +

"(" + iCounter + ")" +

System.IO.Path.GetExtension( oFile.FileName ) ;

iErrorNumber = 201 ;

}

else

{

oFile.SaveAs( sFilePath ) ;

sFileUrl = this.UserFilesPath + sFileName ;

break ;

}

}这样就基本解决了多用户分文件夹上传图片的问题,不过也有缺陷的地方,就是当用户Session超时的时候,用户再使用浏览器上传文件就不会按照指定用户文件夹上传来了,分析这个情况可以得出:这个时候用户通过编辑器上传的文件也就是对编辑器内容作出了修改,但是因为Session超时了,所以可以把做出的修改视作无效,既然修改无效,那用户上传的文件也是没用的,所在我在web.config中又设置了个默认文件上传位置,所有无效文件都会上传到这里,那个回清理的时候也方便多了 不知道哪位大虾还有更好的办法。

出处:http://blog.breakn.net/article.asp?id=388

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
>>返回首页<<
推荐阅读
 
 
频道精选
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
© 2005- 王朝网络 版权所有