如何将图像URL保存到上传到文件夹中的数据库? [英] How can I save image url to database which is uploaded in folder?

查看:103
本文介绍了如何将图像URL保存到上传到文件夹中的数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将图片上传到文件夹中。但是想在数据库中保存图像url。帮助我们。

解决方案

我只是想让你帮我把变量中的图像路径保存起来。这样我就可以将url保存到数据库了。



您已经拥有:

  string  imageName = txtImage.Text; 
FileUserImage.SaveAs(Server.MapPath( 〜/ Images / + imageName + type ));
Response.Write( 上传成功);





所以......

<前lang =cs> 字符串 imageName = txtImage.Text;
string filePath = Server.MapPath( 〜/ Images / + imageName + type);
FileUserImage.SaveAs(filePath);
Response.Write( 上传成功);



然后:

 使用(SqlConnection con =  new  SqlConnection(strConnect))
{
con.Open();
使用(SqlCommand cmd = new SqlCommand( INSERT INTO myTable(myColumn)VALUES(@Path),con))
{
cmd.Parameters.AddWithValue( @ PATH,filePath);
cmd.ExecuteNonQuery();
}
}


让所有人感兴趣。


Link ..

http://aspsnippets.com/Blue/Articles/Upload-images-to-folder-and-display-uploaded-images-in-ASPNet-GridView-using-C-and-VBNet.aspx [ ^ ]







  if (FileUpload1.HasFile)
{
string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
string DbPath =(Server.MapPath( 〜/ Images /)+ fileName);
FileUpload1.PostedFile.SaveAs(DbPath);
}



将DbPath路径保存到数据库。

它将保存文件的完整路径您要保存到文件夹的文件的名称。



所以,在这种情况下,如果想要在某处显示它然后绑定DbPath源,那么它将获得完整的图像。


I have uploaded image in folder. But want to save image url in database. so help me guys.

解决方案

"I just want you to help me to hold image path in variable. So that I can save url to database."

You already have:

string imageName = txtImage.Text;
FileUserImage.SaveAs(Server.MapPath("~/Images/" + imageName + type));
Response.Write("Uploaded successfully");



So...

string imageName = txtImage.Text;
string filePath = Server.MapPath("~/Images/" + imageName + type);
FileUserImage.SaveAs(filePath);
Response.Write("Uploaded successfully");


Then:

using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand cmd = new SqlCommand("INSERT INTO myTable (myColumn) VALUES (@Path)", con))
        {
        cmd.Parameters.AddWithValue("@PATH", filePath);
        cmd.ExecuteNonQuery();
        }
    }


thnks to all for your interest.


Link..
http://aspsnippets.com/Blue/Articles/Upload-images-to-folder-and-display-uploaded-images-in-ASPNet-GridView-using-C-and-VBNet.aspx[^]



if (FileUpload1.HasFile)
  {
      string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
      string DbPath=(Server.MapPath("~/Images/") + fileName);
      FileUpload1.PostedFile.SaveAs(DbPath);
  }


Save DbPath path to database.
it'll save full path with the file name of the File you are saving to the folder.

so, In that case if want to show it somewhere then just bind the DbPath source then it'll get the full image.


这篇关于如何将图像URL保存到上传到文件夹中的数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆