如何将文本信息连同图片一起上传。。。。 <INPUT id="upimage" type="file" runat="server">图片上传到指定目录] 同时将文本信息提交到数据库中 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 文本信息你从哪里输入呢??是不是应该多加一个textbox控件呢?再判断upimage对象的内容类型合法且textbox不为空时,先传upimage到指定目录,指保存textbox的值到数据库. 如果是需要文本信息和图片放在一起,就使用FreeTextBox控件,不过也要注意图片的路径. 3、上传图片CODE: [Copy to clipboard]--------------------------------------------------------------------------------System.Drawing.Image image,newimage; //定义image类的对象 protected string imagePath; //图片路径 protected string imageType; //图片类型 protected string imageName; protected System.Web.UI.WebControls.RadioButtonList choice; //图片名称 System.Drawing.Image.GetThumbnailImageAbort callb =null; //提供一个回调方法,用于确定Image对象在执行生成缩略图操作时何时提前取消执行,如果此方法确定GetThumbnailImage方法应提前停止执行,则返回true,否则返回falseCODE: [Copy to clipboard]--------------------------------------------------------------------------------private void btn_upload_Click(object sender, System.EventArgs e) { string mPath,img_source,img_small; string pid = Request.QueryString["pid"]; string typeid = Request.QueryString["typeid"]; string typef = Request.QueryString["typef"]; if(""!= upImage.PostedFile.FileName) { imagePath = upImage.PostedFile.FileName; //取得图片类型 imageType = imagePath.Substring(imagePath.LastIndexOf(".")+1); //取得图片名称 imageName = DateTime.Now.Year.ToString()+DateTime.Now.Month.ToString()+DateTime.Now.Day.ToString()+DateTime.Now.Hour.ToString()+DateTime.Now.Minute.ToString()+DateTime.Now.Second.ToString()+imagePath.Substring(imagePath.LastIndexOf("\\")+1); if("jpg"!= imageType && "gif"!= imageType ) { Response.Write("<script language='javascript'>alert('对不起!请您选择jpg或者gif格式的图片!');</script>"); return; } else { mPath = Server.MapPath("../../picture"); //建立虚拟路径 upImage.PostedFile.SaveAs(mPath+"\\"+imageName); //保存到虚拟路径 img_source = "picture/" + imageName; //显示原图 image = System.Drawing.Image.FromFile(mPath+"\\"+imageName); //为上传的图片建立引用 newimage = image.GetThumbnailImage(184,148,callb,new System.IntPtr()); //生成缩略图 newimage.Save(Server.MapPath("../../picture")+"\\small"+imageName); //把缩略图保存到指定的虚拟路径 image.Dispose(); //释放image对象占用的资源 newimage.Dispose(); //释放newimage对象的资源 img_small = "picture/" + "small" + imageName; //显示缩略图 string imgid = pub.AddImage(txt_name.Text,img_source,img_small,txt_author.Text,Int32.Parse(pid),Int32.Parse(typeid)); if (imgid != "") { string UserChoice = choice.SelectedValue; switch(UserChoice) { case "1": Response.Redirect ("index.aspx?typeid="+typeid+"&typef="+typef+"&pid="+pid+""); break; case "2": { txt_name.Text = ""; txt_author.Text = ""; } break; } } else { txtMessage.Text ="不好意思,上传图片失败!"; } } } } 给分 好心人帮忙一下,如何将以下JS改成C# JS或者JQuery触发ASP.NET后台方法 急!急!急!怎么给DataList动态添加行 急急急,Oracle 9i客户端连接Oracle8i的服务器乱码问题。 请高手赐教,WEB方式可以创建虚拟目录吗? 我下载了vs.net2005的竟像文件 VCS.img如何去安装呢? 高分求助(分不够再加 要多少都行) 讨论:禁止用户二次登录的一个解决方法 web安装包能否实现这样的功能? 请教各位大侠! 代码有错误,大虾帮忙 关于DataGrid中的DropDownList的用法
是不是应该多加一个textbox控件呢?
再判断upimage对象的内容类型合法且textbox不为空时,先传upimage到指定目录,指保存textbox的值到数据库.
CODE: [Copy to clipboard]
--------------------------------------------------------------------------------System.Drawing.Image image,newimage; //定义image类的对象
protected string imagePath; //图片路径
protected string imageType; //图片类型
protected string imageName;
protected System.Web.UI.WebControls.RadioButtonList choice; //图片名称
System.Drawing.Image.GetThumbnailImageAbort callb =null; //提供一个回调方法,用于确定Image对象在执行生成缩略图操作时何时提前取消执行,如果此方法确定GetThumbnailImage方法应提前停止执行,则返回true,否则返回false
CODE: [Copy to clipboard]
--------------------------------------------------------------------------------private void btn_upload_Click(object sender, System.EventArgs e)
{
string mPath,img_source,img_small;
string pid = Request.QueryString["pid"];
string typeid = Request.QueryString["typeid"];
string typef = Request.QueryString["typef"]; if(""!= upImage.PostedFile.FileName)
{
imagePath = upImage.PostedFile.FileName;
//取得图片类型
imageType = imagePath.Substring(imagePath.LastIndexOf(".")+1);
//取得图片名称
imageName = DateTime.Now.Year.ToString()+DateTime.Now.Month.ToString()+DateTime.Now.Day.ToString()+DateTime.Now.Hour.ToString()+DateTime.Now.Minute.ToString()+DateTime.Now.Second.ToString()+imagePath.Substring(imagePath.LastIndexOf("\\")+1);
if("jpg"!= imageType && "gif"!= imageType )
{
Response.Write("<script language='javascript'>alert('对不起!请您选择jpg或者gif格式的图片!');</script>");
return;
}
else
{
mPath = Server.MapPath("../../picture"); //建立虚拟路径
upImage.PostedFile.SaveAs(mPath+"\\"+imageName); //保存到虚拟路径
img_source = "picture/" + imageName; //显示原图
image = System.Drawing.Image.FromFile(mPath+"\\"+imageName); //为上传的图片建立引用
newimage = image.GetThumbnailImage(184,148,callb,new System.IntPtr()); //生成缩略图
newimage.Save(Server.MapPath("../../picture")+"\\small"+imageName); //把缩略图保存到指定的虚拟路径
image.Dispose(); //释放image对象占用的资源
newimage.Dispose(); //释放newimage对象的资源
img_small = "picture/" + "small" + imageName; //显示缩略图
string imgid = pub.AddImage(txt_name.Text,img_source,img_small,txt_author.Text,Int32.Parse(pid),Int32.Parse(typeid));
if (imgid != "")
{
string UserChoice = choice.SelectedValue;
switch(UserChoice)
{
case "1":
Response.Redirect ("index.aspx?typeid="+typeid+"&typef="+typef+"&pid="+pid+"");
break;
case "2":
{
txt_name.Text = "";
txt_author.Text = "";
}
break;
}
}
else
{
txtMessage.Text ="不好意思,上传图片失败!"; }
}
}
} 给分