使用客户端的File Field控件上传图片[2]

[入库:2006年2月23日] [更新:2007年3月24日]

本文简介:

      //根据时间生成图片名
     string SaveName=DateTime.Now.ToString("yyyyMMddhhmmssfff");
      
     string fn=myFile.PostedFile.FileName;
     strImageName=SaveName+fn.Substring(fn.LastIndexOf("."));//图片名加上图片后缀名
     string strpath=Server.MapPath("")+"
\\UpImages\\"+strImageName;//得到将要保存图片的路径
     myFile.PostedFile.SaveAs(strpath);//把图片保存在此路径中

     bool result=DUI.Insert_UpImage(strImageName,Publishtime);//此为保存图片到数据库中的方法
     if(result)
     {
      Response.Write("<script>alert('图片录入成功')</script>");
      Response.Write("<script>location.href=location.href</script>");
     }
    }
    else
    {
     Response.Write("<script>alert('请选择正确的图片文件')</script>");
     return;
    }
   }
  }

本文关键:使用客户端的File Field控件上传图片
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top