上传图片代码:
int ifile = (int)iFile;
HttpPostedFile postedFile = files[ifile];
string fileName,filesname,fileExtension;
fileName = System.IO.Path.GetFileName(postedFile.FileName);
if (fileName != "")
{
filesname=DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() +DateTime.Now.Hour.ToString() //新生成文件名
+DateTime.Now.Minute.ToString()+ DateTime.Now.Second.ToString() + DateTime.Now.Millisecond + ifile.ToString();
postedFile.SaveAs("d:/Images/" + filesname + fileExtension);
mycookie.Values.Add("filename" + ifile.ToString(), "file:///d:/Images/" + filesname + System.IO.Path.GetExtension(fileName).ToLower());
}
mycookie.Expires = DateTime.Now.AddDays(1);
Response.AppendCookie(mycookie);
上传完图片后,将路径保存在数据库中
读取图片路径时图片出不来
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
ImagesPath += "<img alt='' src='" + ds.Tables[0].Rows[i][2].ToString() + "' height='50px' width='50px' />";
}
------解决方案--------------------------------------------------------
你应该是网络图片,应该用服务器地址+相对路径
------解决方案--------------------------------------------------------
你应该
postedFile.SaveAs(Server.MapPath("~/Images/" + filesname + fileExtension));
数据库存
url = Page.ResolveUrl("~") + "Images/" + filesname + fileExtension;