RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:9:30-18:00
你可能遇到了下面的问题
关闭右侧工具栏
asp.net上传图片并生成缩略图
  • 作者:zhaozj
  • 发表时间:2020-12-23 10:40
  • 来源:未知

<script language="VB" runat="server">Sub UploadFile(sender As Object, e As EventArgs)

If FileUp.PostedFile.ContentLength = 0 ThenFileInfo.Visible = FalseExit SubElseFileInfo.Visible = TrueFDisplay1.Visible = TrueEnd If

FSize.Text ="上传文件大小"+ CStr(FileUp.PostedFile.ContentLength/1024)+"KB"FName.Text = "已上传文件名:"+FileUp.PostedFile.FileName+"<br>"+FName.Text

'写入数据库on error resume nextdim myconn as sqlconnectiondim mycomm as sqlcommanddim sql as stringdim id as integerDim image,anewimage As System.Drawing.Imagedim width,height,newwidth,newheight as integerDim callb As System.Drawing.Image.GetThumbnailImageAbortmyConn=New sqlconnection(ConfigurationSettings.AppSettings("数据库"))myconn.open()sql="insert into picture (姓名,班级,介绍,属性) values ('"&request.cookies("dgxyl").values("dgxylname")&"','"&request.cookies("dgxyl").values("dgxylbj")&"','"&trim(request("TextBox1"))&"','"&request("r1")&"')"Mycomm=New sqlcommand(sql,myconn)mycomm.executenonquery()myconn.close()

Dim myCommand As New SqlCommand("select top 1 id from picture order by id desc", myConn)myCommand.Connection.Open()Dim myReader As SqlDataReader=mycommand.executereader()if myReader.Read() thenid=myReader("id")end ifmyconn.close()'保存图片FileUp.PostedFile.SaveAs( Server.MapPath("/classpic/")&cstr(id)&".jpg" )'生成缩略图image=System.Drawing.Image.FromFile(Server.MapPath("/classpic/"+cstr(id)+".jpg"))width=image.Widthheight=image.heightif width>height thennewwidth=250newheight=image.height/image.Width*newwidthelsenewheight=250newwidth=image.Width/image.height*newheightend ifresponse.write("id="+cstr(id)+"width="+cstr(Width)+";height="+cstr(height)+"  ")response.write("newwidth="+cstr(newwidth)+";newheight="+cstr(newheight)+"<br>")

aNewImage=image.GetThumbnailImage(newwidth,newheight,callb,new System.IntPtr())aNewImage.Save(Server.MapPath("/smallpic/"+cstr(id)+".jpg"))image.Dispose()

Dim FileSplit() As String = Split( FileUp.PostedFile.FileName, "/" )Dim FileName As String = FileSplit(FileSplit.Length-1)Dim Exts() As String = Split( FileName, "." )Dim Ext As String = LCase(Exts(Exts.Length-1))

FDisplay.Text = "<A Target='_blank' HREF='/classpic/"&cstr(id)&".jpg"& "'>查看上传文件</A>"FDisplay1.text="<a href='/picture/default.asp?bj="&cstr(request.cookies("dgxyl").values("dgxylbj"))&"'>返回</a>"End Sub</script><SCRIPT language=JavaScript><!--var requestsubmitted=false;function guestbook_Validator(theForm){//检查是否从新提交if (requestsubmitted==true){  alert("你已经提交了留言,请等待服务器应答!");  return(false);}requestsubmitted=true;