上一篇:ASP.NET中的ViewState >>
asp.net上传图片并同时生成缩略图
Sub UploadFile(sender As Object, e As EventArgs)
If FileUp.PostedFile.ContentLength = 0 Then
FileInfo.Visible = False
Exit Sub
Else
FileInfo.Visible = True
FDisplay1.Visible = True
End If
FSize.Text ="上传文件大小"+ CStr(FileUp.PostedFile.ContentLength/1024)+"KB"
FName.Text = "已上传文件名:"+FileUp.PostedFile.FileName+"<br>"+FName.Text
@#写入数据库
on error resume next
dim myconn as sqlconnection
dim mycomm as sqlcommand
dim sql as string
dim id as integer
Dim image,anewimage As System.Drawing.Image
dim width,height,newwidth,newheight as integer
Dim callb As System.Drawing.Image.GetThumbnailImageAbort
myConn=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() then
id=myReader("id")
end if
myconn.close()
@#保存图片
FileUp.PostedFile.SaveAs( Server.MapPath("\classpic\")&cstr(id)&".jpg" )
@#生成缩略图
image=System.Drawing.Image.FromFile(Server.MapPath("/classpic/"+cstr(id)+".jpg"))
width=image.Width
height=image.height
if width>height then
newwidth=250
newheight=image.height/image.Width*newwidth
else
newheight=250
newwidth=image.Width/image.height*newheight
end if
response.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" onsubmit="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>
<Hr>
<p>注意:</p>
<ol>
<li><b>严禁上传污染环境的照片,否则账号将被删除!</b></li>
<li><font color="#808000"><b>请详细填写照片说明,图片说明不详细将会被视为乱传图片,将会被删除!</b></font></li>
</ol>
<p> </p>
</Body>
</Html>
下一篇:ASP+全新接触(3) {转} >>
相关文章:
- · ASP+ 学习笔记 3
- · asp+中文教程(一)---- -asp+简介、安装、以及如何显示中文
- · asp+中文教程(二)---- Asp+ Web Forms
- · asp+中文教程(三)-- 服务器端控制(一)
- · ASP+ 学习笔记 4
- · ASP+ 学习笔记 2
- · 今日读 asp.net 心得 ---- 比较意识流,神经衰弱勿进
- · 用ASP.NET动态生成图像(转1)
- · Uploading Images to a Database - Part I (转)
- · 在ASP.NET中操作文件的例子(VB)
- · 在ASP.NET中处理 datetime 的一些通用函数(vb)
- · 用ASP.NET动态生成图像(转2)
- · 在 ASP.NET 中使用多个 runat=server form
- · ASP.NET实现HTTP方式获取功能
- · ASP.NET中的XML表单控件
- · Assembly和Import区别
- · 两个获取http页面的c#函数
- · asp.net实现pop功能
- · 深入讲解 ASP+ 验证 (转自ms 一)
- · 深入讲解 ASP+ 验证 (转自ms 二)
- · 使用 ASP+ 列表绑定控件 (转自ms 一)
- · 使用 ASP+ 列表绑定控件 (转自ms 二)
- · 查看服务器磁盘、文件的aspx
- · ASP+全新接触(1) {转}
- · 就是那个上传的。按实际上传时的文件名称保存(不在是test.jpg了)图片可以改大小,图上写字(可选字体...
- · ASP+全新接触(2) {转}
- · 用asp.net写的论坛程序
- · forum.aspx 论坛主页
- · reply.aspx 浏览贴子内容及回复
- · postmessage.aspx 上贴保存
- · .net的几个重要问题
- · 解决问题的方法:(JspFuns与开心的对话录)
- · 控件发布:带日期标注的日历控件。
- · 续上文:由于16K的限制,只能再接一节了。
- · 为什么我在中文win2000+sp1上装的vs.net不能创建各种web application,而英...
- · ASP.NET中密码保护,MD5和SHA1算法的使用
- · ASP。NET连SQL7接口源代码?
- · 我对.Net技术中asp.net应用的一点看法
