首页 新闻 赞助 找找看

ckfinder上传图片 路径的问题 jsp

0
悬赏园豆:5 [已解决问题] 解决于 2013-01-30 19:46

  我用ckeditor和ckfinder实现了上传图片,上传仅仅可以在页面显示。自己在ckfinder中配置了一个路径。

   D:\Tour Copy\YixingTour\WebRoot\ckfinder\uploadFiles  YiXing是我自己建的web工程名,这个路径是上传图片显示在ckfinder上传图片url框中的。但我在uploadFiles中找不到上传的图片,我要的就是要把上传的图片保存到这个文件夹,然后把这个文件夹下的图片路径保存到数据库,怎么做啊?怎样在后台获取ckfinder上传的图片的路径??

   也就是说在  :有D:1.jpg这张图片,我要怎样在后台通过ckfinder上传时获取这个路径??

   帮帮忙啊??

owner_hzh的主页 owner_hzh | 初学一级 | 园豆:6
提问于:2013-01-24 16:09
< >
分享
最佳答案
0

恩不知道你要做什么实现我这钱做过一个类似的,不过就是图片预览时把它放到服务器端了,不过不影响你可以做一下参考。

View Code
 1 protected void BtnPublish_Click(object sender, EventArgs e)
 2         {
 3             int ptype = Convert.ToInt32(this.TextBox2.Text.Trim()); 
 4             HttpPostedFile file = this.FileUpload1.PostedFile;
 5             //获取上传得文件名
 6             string fileName = file.FileName;
 7             //分割文件名
 8             string[] fileTypes = fileName.Split('.');
 9             //获取文件的后缀名
10             string typeName = fileTypes[fileTypes.Length - 1];           
11             //判断文件类型
12             if (typeName == "jpg" || typeName == "gif" || typeName == "png")
13             {
14                 //虚拟路径
15                 string filePath = Server.MapPath("/upimage");
16                 string realName = filePath + "/" + fileName;
17                 //保存路径
18                 file.SaveAs(realName);                
19                 string psrc = "/upimage/" + fileName;
20                 string pname = this.TBname.Text.Trim();
21                 helper = new SqlHelper(strcon);
22                 if(this.TextBox2.Text.Trim()=="1")
23                 {
24                     isFlag = 1;                
25                 }
26                 SqlParameter[] p = new SqlParameter[]
27                 {
28                         new SqlParameter("@pname",SqlDbType.VarChar,20),
29                         new SqlParameter("@psrc",SqlDbType.VarChar),
30                         new SqlParameter("@ptype",SqlDbType.Int,4)            
31                 };
32                 p[0].Value = pname;
33                 p[1].Value = psrc;
34                 p[2].Value = ptype;
35                 try
36                 {
37                     helper.ExecuteNonQuery(sql, p);
38                     string js = "<script>alert('上传成功');</script>";
39                     Response.Write(js);
40                     this.Image1.ImageUrl = "/upimage/" + fileName;
41                     this.TBname.Text = "";
42                     this.FileUpload1.Focus();
43                     this.TextBox2.Text = "";
44                 }
45                 catch (Exception eq)
46                 {
47                     //string js = "<script>alert('文件类型不匹配');</script>";
48                     //Response.Write(js);
49                     Response.Write(eq.Message);
50                 }
51             }
52         }

这个基本基本就是部分主体了,不过有些可以根据你的需要改。不过你要注意,数据库中存放的和cs中的存放路径是不一样的,数据库存放虚拟路径,代码中是物理路径这两个有点混了,你可以试试。

收获园豆:5
妍珊 | 小虾三级 |园豆:1169 | 2013-01-24 16:39

我想问一下,那个ckeditor中 “上传到服务器”按钮事件是写在哪个文件的?我找不到

owner_hzh | 园豆:6 (初学一级) | 2013-01-29 22:10

@owner_hzh: 这个是按钮的单击事件是写到cs代码页面的,另外在传图片时候首先要在你的项目中建一个upimage文件夹确保把图片放到这个文件夹中

妍珊 | 园豆:1169 (小虾三级) | 2013-02-02 18:25
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册