asp.net让FCKEditor上传图片到动态指定的目录
时间:2010-08-27
来源:互联网
比如我们在编辑一篇文章时,,我们总希望FCK的上传图片上传到我们指定的目录,比如按时间.或按ID等等 ;
需要指定路径就得找到FCK上传文件时组合路径的地方.
拿到FCK的.net的源码:FredCK.FCKeditorV2
打开源码目录FileBrowser下的Config.cs文件
就可以看到组合路径方式:
1. internal void LoadConfig()
2. {
3. DefaultSettings();
4.
5. // Call the setConfig() function for the configuration file (config.ascx).
6. SetConfig();
7.
8. // Look for possible UserFilesPath override options.
9. string hostname = System.Configuration.ConfigurationSettings.AppSettings["HostName"];
10.
11. string userFilesPath = HttpContext.Current.Request.QueryString["userfilespath"];
12. if (!string.IsNullOrEmpty(userFilesPath))
13. {
14. userFilesPath = System.Configuration.ConfigurationSettings.AppSettings[ "FCKeditor:UserFilesPath" ] + userFilesPath.Trim('/');
15. }
16.
17. // Session
18. if (string.IsNullOrEmpty(userFilesPath))
19. {
20. userFilesPath = Session["FCKeditor:UserFilesPath"] as string;
21. }
22. // Application
23. if ( userFilesPath == null || userFilesPath.Length == 0 )
24. userFilesPath = Application[ "FCKeditor:UserFilesPath" ] as string;
25.
26. // Web.config file.
27. if ( userFilesPath == null || userFilesPath.Length == 0 )
28. userFilesPath = System.Configuration.ConfigurationSettings.AppSettings[ "FCKeditor:UserFilesPath" ];
29.
30. // config.asxc
31. if ( userFilesPath == null || userFilesPath.Length == 0 )
32. userFilesPath = this.UserFilesPath;
33.
34. if ( userFilesPath == null || userFilesPath.Length == 0 )
35. userFilesPath = DEFAULT_USER_FILES_PATH;
36.
37. // Check that the user path ends with slash ("/")
38. if ( !userFilesPath.EndsWith( "/" ) )
39. userFilesPath += "/";
40.
41. userFilesPath = string.IsNullOrEmpty(hostname) ? userFilesPath : hostname.TrimEnd('/') + userFilesPath;
42. userFilesPath = this.ResolveUrl( userFilesPath );
43.
44. this.UserFilesPath = userFilesPath;
45. }
相信看这段代码不是难事
string hostname = System.Configuration.ConfigurationSettings.AppSettings["HostName"];
string userFilesPath = HttpContext.Current.Request.QueryString["userfilespath"];
这二项是我加上的..我们就是通过URL来动态传递路径的
因为url传路径不安全.我们还是保留FCK的web.config配置路径的方式...只是我们会在配置:FCKeditor:UserFilesPath目录下再生成我们规则的路径
比如:FCKeditor:UserFilesPath配置为:/WebData/
而我们传的路径为 userfilespath=2010/08/09
那么上传文件的路径就是webdata/2010/08/09...这是我们可以动态赋值给FCK的
做到这里还不够..我们得给FCK加个属性可以让我们动态设置路径;
打开源码中的:FCKeditor.cs
找到代码块:#region Configurations Properties
加一个属性在此代码块中:
1. [Category("Configurations")]
2. public string FileMidPath
3. {
4. set { ImageBrowserURL = this.EditorPath + "/filemanager/browser/default/browser.html?Type=Image&Connector=" +
5. this.EditorPath + "/filemanager/connectors/aspx/connector.aspx?userfilespath=" + value; }
6. }
ImageBrowserURL 就是FCK图片浏览的地址;userfilespath就是我们动态设定的路径
现在使用就简单了;
在页面中加上FCK后;在pageload中赋给其路径:这个路径随便你给..GUID等都行.
1. protected void Page_Load(object sender, EventArgs e)
2. {
3. FckContent.FileMidPath = "2010/08/09";
4. }
看看效果:
至此完成路径重写了
当然你可以改得更自由..不过安全也很重要
源码下载:http://www.jiamaocode.com/Cts/1237.html
需要指定路径就得找到FCK上传文件时组合路径的地方.
拿到FCK的.net的源码:FredCK.FCKeditorV2
打开源码目录FileBrowser下的Config.cs文件
就可以看到组合路径方式:
1. internal void LoadConfig()
2. {
3. DefaultSettings();
4.
5. // Call the setConfig() function for the configuration file (config.ascx).
6. SetConfig();
7.
8. // Look for possible UserFilesPath override options.
9. string hostname = System.Configuration.ConfigurationSettings.AppSettings["HostName"];
10.
11. string userFilesPath = HttpContext.Current.Request.QueryString["userfilespath"];
12. if (!string.IsNullOrEmpty(userFilesPath))
13. {
14. userFilesPath = System.Configuration.ConfigurationSettings.AppSettings[ "FCKeditor:UserFilesPath" ] + userFilesPath.Trim('/');
15. }
16.
17. // Session
18. if (string.IsNullOrEmpty(userFilesPath))
19. {
20. userFilesPath = Session["FCKeditor:UserFilesPath"] as string;
21. }
22. // Application
23. if ( userFilesPath == null || userFilesPath.Length == 0 )
24. userFilesPath = Application[ "FCKeditor:UserFilesPath" ] as string;
25.
26. // Web.config file.
27. if ( userFilesPath == null || userFilesPath.Length == 0 )
28. userFilesPath = System.Configuration.ConfigurationSettings.AppSettings[ "FCKeditor:UserFilesPath" ];
29.
30. // config.asxc
31. if ( userFilesPath == null || userFilesPath.Length == 0 )
32. userFilesPath = this.UserFilesPath;
33.
34. if ( userFilesPath == null || userFilesPath.Length == 0 )
35. userFilesPath = DEFAULT_USER_FILES_PATH;
36.
37. // Check that the user path ends with slash ("/")
38. if ( !userFilesPath.EndsWith( "/" ) )
39. userFilesPath += "/";
40.
41. userFilesPath = string.IsNullOrEmpty(hostname) ? userFilesPath : hostname.TrimEnd('/') + userFilesPath;
42. userFilesPath = this.ResolveUrl( userFilesPath );
43.
44. this.UserFilesPath = userFilesPath;
45. }
相信看这段代码不是难事
string hostname = System.Configuration.ConfigurationSettings.AppSettings["HostName"];
string userFilesPath = HttpContext.Current.Request.QueryString["userfilespath"];
这二项是我加上的..我们就是通过URL来动态传递路径的
因为url传路径不安全.我们还是保留FCK的web.config配置路径的方式...只是我们会在配置:FCKeditor:UserFilesPath目录下再生成我们规则的路径
比如:FCKeditor:UserFilesPath配置为:/WebData/
而我们传的路径为 userfilespath=2010/08/09
那么上传文件的路径就是webdata/2010/08/09...这是我们可以动态赋值给FCK的
做到这里还不够..我们得给FCK加个属性可以让我们动态设置路径;
打开源码中的:FCKeditor.cs
找到代码块:#region Configurations Properties
加一个属性在此代码块中:
1. [Category("Configurations")]
2. public string FileMidPath
3. {
4. set { ImageBrowserURL = this.EditorPath + "/filemanager/browser/default/browser.html?Type=Image&Connector=" +
5. this.EditorPath + "/filemanager/connectors/aspx/connector.aspx?userfilespath=" + value; }
6. }
ImageBrowserURL 就是FCK图片浏览的地址;userfilespath就是我们动态设定的路径
现在使用就简单了;
在页面中加上FCK后;在pageload中赋给其路径:这个路径随便你给..GUID等都行.
1. protected void Page_Load(object sender, EventArgs e)
2. {
3. FckContent.FileMidPath = "2010/08/09";
4. }
看看效果:
至此完成路径重写了
当然你可以改得更自由..不过安全也很重要
源码下载:http://www.jiamaocode.com/Cts/1237.html
作者: df82325542 发布时间: 2010-08-27
不错,支持
作者: wuyq11 发布时间: 2010-08-27
作者: df82325542 发布时间: 2010-08-27
观摩 Mark下
作者: sibiyellow 发布时间: 2010-08-27
学习了
作者: studentliudong 发布时间: 2010-08-27
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28