asp.net上传图片并生成缩略图
发布日期:2021-06-30 19:17:48
浏览次数:3
分类:技术文章
本文共 3553 字,大约阅读时间需要 11 分钟。
<script language="VB" runat="server">
Sub UploadFile(sender As Object, e As EventArgs)If FileUp.PostedFile.ContentLength = 0 Then
FileInfo.Visible = FalseExit SubElseFileInfo.Visible = TrueFDisplay1.Visible = TrueEnd IfFSize.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;return (true);
}//--></SCRIPT><Html><Body BgColor=White><H3 align="center">请正确填写下面各项</h3><Hr></H3><Div id="FileInfo" Visible="False" runat="server"><Asp:Label id="FSize" runat="server"/><br><Asp:Label id="FName" runat="server"/><br><Asp:Label id="FDisplay" runat="server"/><Asp:Label id="FDisplay1" runat="server"/></Div><Form Enctype="multipart/form-data" οnsubmit="return guestbook_Validator(this)" runat="server">上传文件<Input Type="File" id="FileUp" runat="server" size="20"><br>图片属性:<input type="radio" value="<%=request.cookies("dgxyl").values("dgxylbj")%>" name="R1" checked>本班<input type="radio" value="全校" name="R1">全校(本班则只在本班显示,全校则在全校显示)<P>图片说明:<br><asp:TextBox id="TextBox1" runat="server" Width="233px" Height="141px"></asp:TextBox> <asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="请输入图片说明"></asp:RequiredFieldValidator><br><Asp:button id="Upload" OnClick="UploadFile" Text="上传图片" runat="server"/></form></Body></Html>转载地址:https://linuxstyle.blog.csdn.net/article/details/211979 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
表示我来过!
[***.240.166.169]2024年04月07日 03时32分49秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
matlab中uint8,double,im2double和im2uint8的区别
2019-04-30
数字图像处理总复习
2019-04-30
图像去噪(包含修正的阿尔法均值滤波及通用滤波方法代码)
2019-04-30
SVM进行人脸检测
2019-04-30
C++学习笔记
2019-04-30
图像处理学习笔记
2019-04-30
Machine Learning Onramp on MATLAB 学习笔记
2019-04-30
Machine Learning with MATLAB 1.1 to 2.2
2019-04-30
Learning DSP with MATLAB
2019-04-30
用MATLAB实现m序列的生成(MATLAB 2021a适用)
2019-04-30
MATLAB函数备忘(定期更新)
2019-04-30
13行MATLAB代码实现网络爬虫 爬取NASA画廊星图
2019-04-30
MATLAB指定路径保存图片方法
2019-04-30
Python一键获取微信推送封面图
2019-04-30
油猴脚本:微信推送浏览功能拓展
2019-04-30
JavaScript DOM对象操作详解
2019-04-30
JavaScript 表单操作与MD5加密
2019-04-30
JAVA学习笔记4 - 循环与分支结构
2019-04-30
JAVA学习笔记6 - 数组
2019-04-30