用户登录  |  用户注册
首 页商业源码原创产品编程论坛
当前位置:PB创新网文章中心.Net

用asp.net实现将上传的图片变小存入数据库

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2009-03-12 15:52:19

我校的学生网:www.ehang.com.cn中有校友录和图库等的项目有上传图片的功能,我将图片数据存入数据库中,需要将图片变小后和原图片一块存入数据库中,这样先可显示很多小图,点击后再显示大图!在asp.net中是这么做的:
changimage.aspx中代码:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="changimage.aspx.vb" Inherits="uploadimage.changimage"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title></title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" enctype="multipart/form-data" runat="server">
<FONT face="宋体"><INPUT id="File1" style="Z-INDEX: 101; LEFT: 291px; WIDTH: 180px; POSITION: absolute; TOP: 119px; HEIGHT: 45px" type="file" size="10" name="File1" runat="server"> <asp:Button id="cmdupload" style="Z-INDEX: 103; LEFT: 402px; POSITION: absolute; TOP: 194px" runat="server" Text="上传图片" Width="81px" Height="42px"></asp:Button>
</FONT>
</form>
</body>
</HTML>
changimage.aspx.vb中代码如下:
Public Class changimage
Inherits System.Web.UI.Page
Protected WithEvents cmddemo As System.Web.UI.WebControls.Button
Protected WithEvents cmdupload As System.Web.UI.WebControls.Button
Protected WithEvents SqlConn As System.Data.SqlClient.SqlConnection
Protected WithEvents SqlComm As System.Data.SqlClient.SqlCommand
Protected WithEvents File1 As System.Web.UI.HtmlControls.HtmlInputFile #Region " Web Form Designer Generated Code "'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.SqlConn = New System.Data.SqlClient.SqlConnection()
Me.SqlComm = New System.Data.SqlClient.SqlCommand()End SubPrivate Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
Form Designer
InitializeComponent()
End Sub#End RegionPrivate Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End SubPrivate Sub cmdupload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdupload.Click
Dim image As System.Drawing.Image, newimage As System.Drawing.Image
Dim callb As System.Drawing.Image.GetThumbnailImageAbort
Dim f As System.IO.File, fs As System.IO.FileStream
Dim temppath As String
Dim bigdata As Byte(), smalldata As Byte() '大图片数据、小图片数据
Dim pic As System.Data.SqlClient.SqlParameter, picsmall As System.Data.SqlClient.SqlParameter
'检察上传文件是否合标准,check函数是我根据网站需要写的了
If check(File1.PostedFile.FileName) <> "ok" Then
Response.Write(check(File1.PostedFile.FileName))
Exit Sub
End If
'设置临时路径,为了防止多用户访问时的冲突,设了一个application对象
If Application("image") = "" Then

Tags:

作者:佚名

文章评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论

栏目导航

本类热门阅览

相关文章

PB创新网ourmis.com】Copyright © 2000-2009 . All Rights Reserved .
页面执行时间:7,406.25000 毫秒
Email:ourmis@126.com QQ:2322888 蜀ICP备05006790号