图像未从asp.net 中的给定路径加载,这里是场景。我已经上传一个图像到文件夹使用asp.net,并插入它的SQL Server数据库的路径,但是当我尝试从我的asp应用程序的路径中获取图像“路径是正确的”,但图像加载失败。没有错误。图片不能从路径加载
这里是上传数据
if (FileUpload1.HasFile && TextArea1.Value != null)
{
string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
string path = Server.MapPath("/admin/images/" +fileName);
FileUpload1.PostedFile.SaveAs(Server.MapPath("/admin/images/" + fileName));
//Response.Write("<script>alert('" + path + "');</script>");
string ta1 = TextArea1.Value;
string sql = "UPDATE homep SET img = '" + path + "', description= '" + ta1.Replace("'", "''") + "' WHERE id = 1;";
cmd = new SqlCommand(sql, con);
if (cmd.ExecuteNonQuery() > 0)
{
Response.Write("<script>alert('Updation Success ..!');</script>");
}
}
这里的代码用于获取数据
dr.Read();
Response.Write("<img src='"+dr["img"].ToString()+"' class='img-responsive'/>");
dr.Close();
This Image shows final output as i am getting content but not getting image from path
感谢您的解决方案,但我使用数据库检索路径。所以我可以把这个方法,我从数据库 –
是的路径。在图像的src中,您仍然像在初始代码中那样指定路径。该路径作为URL参数传递(参见?path =)到我建议的actionmethod。此方法将从硬盘读取文件并将其提供给浏览器。 – middelpat
非常感谢,我完成了。 –