产品系统加购物系统 我想做一个产品系统,但是这几天在这个图片上传不知道怎么做下去了.不知道有没什么好的建议? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 楼主表单form哪里要修改的,再随便找个代码就可以用啦。 我这里有2个办法,一个就是用HTM编辑器上传,但是我不用会,看的头昏了.一个就是自己用代码. 代码是这样写的:System.Drawing.Image image,newimage; //图片路径 protected string imagePath; //图片类型 protected string imageType; //图片名称 protected string imageName; protected System.Web.UI.HtmlControls.HtmlInputFile upImage; //提供一个回调方法,用于确定Image对象在执行生成缩略图操作时何时提前取消执行 //如果此方法确定 GetThumbnailImage 方法应提前停止执行,则返回 true;否则返回 false System.Drawing.Image.GetThumbnailImageAbort callb = null;private void Button1_Click(object sender, System.EventArgs e) { string mPath; if("" != upImage.PostedFile.FileName) { imagePath= upImage.PostedFile.FileName; //取得图片类型 imageType= imagePath.Substring(imagePath.LastIndexOf(".")+1); //取得图片名称 imageName = imagePath.Substring(imagePath.LastIndexOf("\\")+1); //判断是否是JPG或者GIF图片,这里只是举个例子,并不一定必须是这两种图片 if("jpg" != imageType && "gif" != imageType) { Response.Write("<script language='javascript'> alert('对不起!请您选择jpg或者gif格式的图片!');</script>"); return; } else { //建立虚拟路径 mPath=Server.MapPath("upFile"); //保存到虚拟路径 upImage.PostedFile.SaveAs(mPath+"\\"+imageName); //显示原图 //imageSource.ImageUrl = "upFile/"+imageName; //为上传的图片建立引用 //image=System.Drawing.Image.FromFile(mPath+"\\"+imageName); //生成缩略图 newimage=image.GetThumbnailImage(500,500,callb,new System.IntPtr()); //把缩略图保存到指定的虚拟路径 newimage.Save(Server.MapPath("upFile")+"\\small"+imageName); //释放image对象占用的资源 image.Dispose(); //释放newimage对象的资源 newimage.Dispose(); //显示缩略图 //imageSmall.ImageUrl = "upFile/"+"small"+imageName; SqlConnection conn=new SqlConnection("server=(local);database=mydb;uid=sa;pwd=sa"); conn.Open(); string sql="insert into new(name,img,conent) values('"+TextBox1.Text+"','"+imageName.ToString()+"','"+TextBox2.Text+"')"; SqlCommand comm=new SqlCommand(sql); comm.ExecuteNonQuery(); conn.Close(); conn.Dispose(); Response.Write("上传成功!");但是是错误的,说我的未将对象引用设置到对象的实例。newimage=image.GetThumbnailImage(500,500,callb,new System.IntPtr());头都昏了 【共同关注】如何获取youku,ku6,土豆等视频的第一帧?【高手入内】 怎么让页面中的文字滚动起来? 如何实现像土豆那样将视频转换为flv格式的?? 触发事件问题 关于连接mysql的问题 CASE WHEN 的问题(Hurry) 有人能推荐一本ASP.NET的书吗 如何不显示gridview或是griddata中值为空的行? 竟有这种事:Treeview在服务器端竖向显示正常,但在客户端却横向排列,怎么回事啊? 框架页参数传递的问题! 上传大文件???????// 哪里有微软官方论坛源码
一个就是自己用代码.
System.Drawing.Image image,newimage;
//图片路径
protected string imagePath;
//图片类型
protected string imageType;
//图片名称
protected string imageName;
protected System.Web.UI.HtmlControls.HtmlInputFile upImage;
//提供一个回调方法,用于确定Image对象在执行生成缩略图操作时何时提前取消执行
//如果此方法确定 GetThumbnailImage 方法应提前停止执行,则返回 true;否则返回 false
System.Drawing.Image.GetThumbnailImageAbort callb = null;private void Button1_Click(object sender, System.EventArgs e)
{
string mPath; if("" != upImage.PostedFile.FileName)
{
imagePath= upImage.PostedFile.FileName;
//取得图片类型
imageType= imagePath.Substring(imagePath.LastIndexOf(".")+1);
//取得图片名称
imageName = imagePath.Substring(imagePath.LastIndexOf("\\")+1);
//判断是否是JPG或者GIF图片,这里只是举个例子,并不一定必须是这两种图片
if("jpg" != imageType && "gif" != imageType)
{
Response.Write("<script language='javascript'> alert('对不起!请您选择jpg或者gif格式的图片!');</script>");
return;
}
else
{
//建立虚拟路径
mPath=Server.MapPath("upFile");
//保存到虚拟路径
upImage.PostedFile.SaveAs(mPath+"\\"+imageName);
//显示原图
//imageSource.ImageUrl = "upFile/"+imageName;
//为上传的图片建立引用
//image=System.Drawing.Image.FromFile(mPath+"\\"+imageName);
//生成缩略图
newimage=image.GetThumbnailImage(500,500,callb,new System.IntPtr());
//把缩略图保存到指定的虚拟路径
newimage.Save(Server.MapPath("upFile")+"\\small"+imageName);
//释放image对象占用的资源
image.Dispose();
//释放newimage对象的资源
newimage.Dispose();
//显示缩略图
//imageSmall.ImageUrl = "upFile/"+"small"+imageName;
SqlConnection conn=new SqlConnection("server=(local);database=mydb;uid=sa;pwd=sa");
conn.Open();
string sql="insert into new(name,img,conent) values('"+TextBox1.Text+"','"+imageName.ToString()+"','"+TextBox2.Text+"')"; SqlCommand comm=new SqlCommand(sql);
comm.ExecuteNonQuery();
conn.Close();
conn.Dispose(); Response.Write("上传成功!");
但是是错误的,说我的未将对象引用设置到对象的实例。
newimage=image.GetThumbnailImage(500,500,callb,new System.IntPtr());
头都昏了