当我上传存储在文件夹中的图像但未在图像控制中显示时。怎么解决这个? 我在更新面板中使用文件上传和图像控制。
private void StartUpLoad()
{
string imgName = fuimage.FileName;
int imgSize = fuimage.PostedFile.ContentLength;
string ext = System.IO.Path.GetExtension(this.fuimage.PostedFile.FileName);
if (fuimage.PostedFile != null && fuimage.PostedFile.FileName != "")
{
if (imgSize > 2097151)
{
lblimgname.Text = "alert('File is too big.')";
}
if (ext.ToUpper().Trim() != ".JPG" && ext.ToUpper() != ".PNG" && ext.ToUpper() != ".JPEG")
{
lblimgname.Text = "alert('Please choose only .jpg, .png and .jpeg image types!')";
}
else
{
string fileName = fuimage.FileName.ToString();
string uploadFolderPath = "~/staff_image/";
string filePath = HttpContext.Current.Server.MapPath(uploadFolderPath);
fuimage.SaveAs(filePath + "\\" + fileName);
imgstaff.ImageUrl = "~/Event_Image/" + fuimage.FileName.ToString();
lblimgname.Text = fuimage.FileName.ToString();
Response.Write("Image Saved Successfully!");
}
}
}
答案 0 :(得分:2)
好的,请检查以下两行:
string uploadFolderPath = "~/staff_image/";
和此:
imgstaff.ImageUrl = "~/Event_Image/" + fuimage.FileName.ToString();
所以基本上是在“staff_image”文件夹中上传图像,但是后来你在“Event_Image”文件夹中显示/显示它,所以上传的图像不存在于“Event_Image”位置!
所以在这一行做出这个改变:
imgstaff.ImageUrl = "~/staff_image/" + fuimage.FileName.ToString();
我已经测试过了,现在它的工作正常了从该位置正确显示图像。