在C#中,如何实现上传图像的功能……
答案:3 悬赏:30
解决时间 2021-01-21 23:24
- 提问者网友:溺爱和你
- 2021-01-21 18:58
在C#中,如何实现上传图像的功能……
最佳答案
- 二级知识专家网友:底特律间谍
- 2021-01-21 19:18
参考代码如下:string filepath = FileUpload1.PostedFile.FileName;
string filename = filepath.Substring(filepath.LastIndexOf( "\\ "));
string fileEx = filepath.Substring(filepath.LastIndexOf( ". ")+1);
string serverpath = "C:/aa/upload/ " + filename;
string dbpath = "\\upload\\ " + filename;
if (fileEx == "jpg " || fileEx == "bmp " || fileEx == "gif ")
{
FileUpload1.PostedFile.SaveAs(serverpath);
Response.Write( "成功 ");
Image1.ImageUrl = @ "..\aa\upload\ " + filename;
}
else
{
Response.Write( "失败 ");
}
string sql = "insert into gc_carno(id,carno,model,carphoto) values(100, ' "+TextBox1.Text+ " ', ' "+TextBox2.Text+ " ', ' "+dbpath+ " ') ";
OracleConnection conn = sda.getoracleconnection();
conn.Open();
OracleCommand cmd = new OracleCommand(sql,conn);
int i = cmd.ExecuteNonQuery();
if (i == 1)
{
Response.Write( " ");
}
else
{
Response.Write( " ");
}
在数据库存储的是服务器图片的物理地址,数据类型是varchar型。
string filename = filepath.Substring(filepath.LastIndexOf( "\\ "));
string fileEx = filepath.Substring(filepath.LastIndexOf( ". ")+1);
string serverpath = "C:/aa/upload/ " + filename;
string dbpath = "\\upload\\ " + filename;
if (fileEx == "jpg " || fileEx == "bmp " || fileEx == "gif ")
{
FileUpload1.PostedFile.SaveAs(serverpath);
Response.Write( "成功 ");
Image1.ImageUrl = @ "..\aa\upload\ " + filename;
}
else
{
Response.Write( "失败 ");
}
string sql = "insert into gc_carno(id,carno,model,carphoto) values(100, ' "+TextBox1.Text+ " ', ' "+TextBox2.Text+ " ', ' "+dbpath+ " ') ";
OracleConnection conn = sda.getoracleconnection();
conn.Open();
OracleCommand cmd = new OracleCommand(sql,conn);
int i = cmd.ExecuteNonQuery();
if (i == 1)
{
Response.Write( " ");
}
else
{
Response.Write( " ");
}
在数据库存储的是服务器图片的物理地址,数据类型是varchar型。
全部回答
- 1楼网友:底特律间谍
- 2021-01-21 21:05
我暂时保留我的看法!
- 2楼网友:上分大魔王
- 2021-01-21 19:45
学习了,一个上传到服务器地址serverpath ,一个数据库地址dbpath
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯