无组件上传图片到数据库中,最完整解决方案

王朝other·作者佚名  2006-11-24
宽屏版  字体: |||超大  

无组件上传图片到数据库中,最完整解决方案

-------------------------------------------------------------------

':::::: 此程序属扬子原创 ::::::::::::::::::

':::::: 在sql2000,2000s中测试通过::::::::

':::::: 联系我:QQ:21112856,Email:yangzinet@hotmail.com:::::::::

':::::: http://www.tingfo.net ::::::

up.htm

<!--#include file="inc/domin.asp"-->

<!--#include file="conn.asp"-->

<html>

<head>

<title><% =webname %></title>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<link rel="stylesheet" href="main.css" type="text/css">

<style type="text/css">

<!--

.tx1 { height: 20px; width: 30px; font-size: 9pt; border: 1px solid; border-color: black black

#000000; color: #0000FF}

-->

</style>

<script language="JavaScript">

<!--

var bgc_on=new Array("#74D738","#FF9C17","#3278AB","#486177","#078C00","#007ECA")

var bgc_off=new Array("#4CAD12","FFB859","5F9FD0","577590","08A700","009FFF")

function turnon(obj1,id){

obj1.style.background=bgc_on[id];

}

function turnoff(obj1,id){

obj1.style.background=bgc_off[id];

}

//-->

</script>

<SCRIPT language=javascript>

function check_input()

{

if (Frm.pic.value=="")

{ alert("请选择要上传的图片");

return false;

}

if (Frm.type.value=="")

{ alert("请选择图片类型");

return false;

}

if (Frm.thetext.value=="")

{ alert("请输入照片说明");

return false;

}

return true;

}

</SCRIPT>

</head>

<body bgcolor="#555555" text="#000000" leftmargin="0" topmargin="0">

<table width=755 cellpadding=0 cellspacing=0 border=0 bgcolor=#ffffff align="center">

<tr>

<td height=100><img src="img/top.gif" align="top">

</table>

<!--#include file="inc/mulu.asp"-->

<table width=755 cellpadding=0 cellspacing=0 border=0 bgcolor=#ffffff align="center" bordercolor=#000000>

<tr>

<td height=400 width=180 bgcolor=#D1E9D5 style="border-right: 1px #0E801E solid">

<table width=100% height=100% cellpadding=0 cellspacing=0 border=0 align="center" bordercolor=#000000>

<tr><td height=30 align="center" class=L15><font color=#E96D08>欢迎你:<% =username %> 管理中心</font>

<tr><td height=23 align="center" class=L15 bgcolor=#4CAD12 style="border-top:0px #0E801E solid; border-bottom:1px #0E801E solid;"><font color=#C2F009 class=yinying>管 理 中 心</font>

<tr><td height=20 class=L13>

<!--#include file="inc/centermulu.asp"-->

<tr><td height=5>

<tr><td>

</table>

<td>

<%

set rs=server.createobject("adodb.recordset")

sql="select * from photo where author='"&username&"'"

rs.open sql,conn,1,1

%>

<table cellpadding=0 cellspacing=0 border=0 width=100% height=100%>

<tr><td height=3>

<tr><td height=3 bgcolor=#ffffff background=img/bj3.gif>

<tr><td height=20 valign="bottom" bgcolor=#eeeeee> 现在位置: 98243班 - 管理中心 - 添加新闻

<tr><td height=3 bgcolor=#eeeeee style="border-bottom: 1px #cccccc solid"><p style="font-size:1pt">

<tr><td height=20 valign="bottom"> <font color=green><% =username %>:你一共上传了 <font color=red><% =rs.recordcount %></font> 张照片</font> <a href="adminphoto.asp"><font color=red><u>管理以前上传的照片</u></font></a>

<tr><td bgcolor=#ffffff valign=top>

<table cellpadding=0 cellspacing=0 border=0 width=95% height=100% align="center">

<form action=addphoto.asp method=post name=Frm onSubmit="return check_input()" enctype="multipart/form-data">

<tr><td height=20 colspan=2>

<tr><td height=25 width=15% align="right" class=L13>选择照片: <td> <input NAME="pic" TYPE="FILE" class="tx1" style="width:300"> <font color=red>拒绝色情、写真图等</font>

<tr><td height=25 width=20% align="right" class=L13>照片分类: <td> <select name="type">

<option selected value="">选择类型</option>

<option value="班级合影">班级合影</option>

<option value="个人照片">个人照片</option>

<option value="恩师照片">恩师照片</option>

<option value="情人照片">情人照片</option>

<option value="友人照片">友人照片</option>

<option value="其他照片">其他照片</option>

</select>

<tr><td height=25 width=20% align="right" class=L13>照片说明: <td> <textarea name="thetext" cols="46" rows="7" style="border:1px double rgb(88,88,88);font:9pt">

</textarea> <font color=red>最多20个字符</font>

<tr><td height=5 colspan=2>

<tr><td height=25 colspan=2 align="center">

<input type="submit" name="Submit" value=" 提 交 " style="border:1px double rgb(88,88,88);font:9pt">

<input type="reset" name="Reset" value=" 重 写 " style="border:1px double rgb(88,88,88);font:9pt">

<tr><td colspan=2>

</tr></form>

</table>

</table>

</table>

<!--#include file="inc/footer.asp"-->

</body>

</html>

fupload.inc

<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>

'限制上传图片大小

Dim UploadSizeLimit

'********************************** 得到上传数据 **********************************

Function GetUpload()

Dim Result

Set Result = Nothing

If Request.ServerVariables("REQUEST_METHOD") = "POST" Then 'Request method must be "POST"

Dim CT, PosB, Boundary, Length, PosE

CT = Request.ServerVariables("HTTP_Content_Type") 'reads Content-Type header

If LCase(Left(CT, 19)) = "multipart/form-data" Then 'Content-Type header must be "multipart/form-data"

'This is upload request.

'Get the boundary and length from Content-Type header

PosB = InStr(LCase(CT), "boundary=") 'Finds boundary

If PosB > 0 Then Boundary = Mid(CT, PosB + 9) 'Separetes boundary

Length = CLng(Request.ServerVariables("HTTP_Content_Length")) 'Get Content-Length header

if "" & UploadSizeLimit<>"" then

UploadSizeLimit = clng(UploadSizeLimit)

if Length > UploadSizeLimit then

' on error resume next 'Clears the input buffer

' response.AddHeader "Connection", "Close"

' on error goto 0

Request.BinaryRead(Length)

Err.Raise 2, "GetUpload", "Upload size " & FormatNumber(Length,0) & "B exceeds limit of " & FormatNumber(UploadSizeLimit,0) & "B"

exit function

end if

end if

If Length > 0 And Boundary <> "" Then 'Are there required informations about upload ?

Boundary = "--" & Boundary

Dim Head, Binary

Binary = Request.BinaryRead(Length) 'Reads binary data from client

'Retrieves the upload fields from binary data

Set Result = SeparateFields(Binary, Boundary)

Binary = Empty 'Clear variables

Else

Err.Raise 10, "GetUpload", "Zero length request ."

End If

Else

Err.Raise 11, "GetUpload", "No file sent."

End If

Else

Err.Raise 1, "GetUpload", "Bad request method."

End If

Set GetUpload = Result

End Function

Function SeparateFields(Binary, Boundary)

Dim PosOpenBoundary, PosCloseBoundary, PosEndOfHeader, isLastBoundary

Dim Fields

Boundary = StringToBinary(Boundary)

PosOpenBoundary = InstrB(Binary, Boundary)

PosCloseBoundary = InstrB(PosOpenBoundary + LenB(Boundary), Binary, Boundary, 0)

Set Fields = CreateObject("Scripting.Dictionary")

Do While (PosOpenBoundary > 0 And PosCloseBoundary > 0 And Not isLastBoundary)

'Header and file/source field data

Dim HeaderContent, FieldContent

'Header fields

Dim Content_Disposition, FormFieldName, SourceFileName, Content_Ty

[1] [2] 下一页

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有