你利用 postedFileInputStream 生成缩略图后,缩略图可以直接保存到服务器上成为文件,不需要再保存到 postedFile 中了。protected void Button1_Click(object sender, EventArgs e)
{
//上传
string connection = WebConfigurationManagerConnectionStrings["ConnectionString1"]ConnectionString;
SqlConnection conn = new SqlConnection(connection);
string path = ServerMapPath("~/Picture");
string filepath = FileUpload1PostedFileFileName;
string name = filepathSubstring(filepathLastIndexOf("\\")+1);//获取文件名
string Extend = filepathSubstring(filepathLastIndexOf("")+1);//获取格式名
if (Extend == "jpg" || Extend == "gif" || Extend == "bmp")
{
FileUpload1SaveAs(path + "\\" + name);
string filepath1 = "~/Picture/" + name; //这里的Picture是指你要上传到的服务器文件夹 可以自己改
connOpen();
string sql = "insert into Picture values('" + filepath1 + "')";
SqlCommand cmd = new SqlCommand(sql, conn);
cmdExecuteNonQuery();
ResponseWrite("<script>alert('插入成功!')</script>");
}
else
{
ResponseWrite("<script>alert('格式不正确!')</script>");
}
}
其实你这个问题在百度很多啊 最后希望可以帮助你
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)