|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
缺点:安全性不是太差了,还行,只要你充分利用系统自带的工具;唯一缺点就是执行效率慢,如何进行网站优化以后,效果会比较好。上传|无组件-----------------------------
表单填写页的内容:
-----------------------------
<html>
<head>
<metaname="Author"content="SanderDuivestein">
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
<metaname="GENERATOR"content="MicrosoftFrontPage4.0">
<metaname="ProgId"content="FrontPage.Editor.Document">
<title>将当地的文件上载到数据库</title>
</head>
<body>
<fontsize="2"size="2"><br>
</font>
<formname="frmUpload"method="post"enctype="multipart/form-data"action="Upload.asp">
<tablecellspacing="0"cellpadding="0"width="490">
<tr>
<tdwidth="167">
<palign="right"><fontsize="2"size="2">请选择文件:</font></p>
</td>
<tdwidth="319"><fontsize="2"size="2"><inputtype="file"name="vFileName"></font></td>
</tr>
<tr>
<tdalign="right"width="167"><fontsize="2"size="2">文件申明1:</font></td>
<tdwidth="319"><inputname="shuoming"size="32"></font></td>
</tr>
<tr>
<tdalign="right"width="167"><fontsize="2"size="2">文件申明2:</font></td>
<tdwidth="319"><inputname="shuoming_2"size="32"</td>
</tr>
<tdwidth="167"></td>
<tdwidth="319">
<palign="left"><fontsize="2"size="1"><inputtype="submit"style="background-image:url(images/back.jpg);cursor:hand;font-sizd:smaller;left:0px;width:94;top:5px;height:25"value="上载"style="background-image:url(images/back.jpg);cursor:hand;font-sizd:smaller;left:0px;width:94;top:5px;height:25"size="23"></font></p>
</td>
<tr>
<tdcolspan="2"align="right"width="487"></td>
</tr>
</table>
</form>
</body>
</html>
----------------------------------
Upload.asp的内容:
----------------------------------
<%
Response.Buffer=TRUE
Response.Clear
byteCount=Request.TotalBytes
RequestBin=Request.BinaryRead(byteCount)
response.binarywriterequestbin
获得表单的全体内容
DimUploadRequest
SetUploadRequest=CreateObject("Scripting.Dictionary")
UploadRequest布局将用来寄存表单
PosBeg=1
PosEnd=InstrB(PosBeg,RequestBin,StoB(chr(13)))
boundary=MidB(RequestBin,PosBeg,PosEnd-PosBeg)
求字段间的分开串(即:-----------------------------7d029e347d8)
boundaryPos=InstrB(1,RequestBin,boundary)
Dountil(boundaryPos=InstrB(RequestBin,boundary&StoB("--")))
Membersvariableofobjectsareputinadictionaryobject
DimUploadControl
SetUploadControl=CreateObject("Scripting.Dictionary")
Getanobjectname
Pos=InstrB(BoundaryPos,RequestBin,StoB("Content-Disposition"))
Pos=InstrB(Pos,RequestBin,StoB("name="))
PosBeg=Pos+6
PosEnd=InstrB(PosBeg,RequestBin,StoB(chr(34)))
Name=BtoS(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
PosFile=InstrB(BoundaryPos,RequestBin,StoB("filename="))
PosBound=InstrB(PosEnd,RequestBin,boundary)
response.write"<hr>"
response.write"name="&name&"<BR>"
name为表单项的名字
Testifobjectisoffiletype
IfPosFile0AND(PosFile<PosBound)Then
PosBeg=PosFile+10
PosEnd=InstrB(PosBeg,RequestBin,StoB(chr(34)))
FileName=BtoS(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
response.write"<BR>"
response.write"filename="&filename&"<BR>"
filename为全路径文件名(假如是文件范例话)
UploadControl.Add"FileName",FileName
Pos=InstrB(PosEnd,RequestBin,StoB("Content-Type:"))
PosBeg=Pos+14
PosEnd=InstrB(PosBeg,RequestBin,StoB(chr(13)))
ContentType=BtoS(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
UploadControl.Add"ContentType",ContentType
response.write"filetype="&ContentType&"<BR>"
response.write"<BR>"
PosBeg=PosEnd+4
PosEnd=InstrB(PosBeg,RequestBin,boundary)-2
Value=MidB(RequestBin,PosBeg,PosEnd-PosBeg)
filesize=Posend-Posbeg
UploadControl.Add"FileSize",filesize
response.write"value="
response.binarywritevalue
response.write"<BR>"
Else
Pos=InstrB(Pos,RequestBin,StoB(chr(13)))
PosBeg=Pos+4
PosEnd=InstrB(PosBeg,RequestBin,boundary)-2
Value=BtoS(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
response.write"value="&value&"<BR>"
value为表单项的值,假如为文件项,则value为一长串二进制码
EndIf
UploadControl.Add"Value",Value
UploadRequest.Addname,UploadControl
UploadRequest增添一个Key为name的项,此项的value还是一个dixtionary工具
BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)
Loop
contentType=UploadRequest.Item("vFileName").Item("ContentType")
filesize=UploadRequest.Item("vFileName").Item("FileSize")
filepathname=UploadRequest.Item("vFileName").Item("FileName")
filename=Right(filepathname,Len(filepathname)-InstrRev(filepathname,""))
filevalue=UploadRequest.Item("vFileName").Item("Value")
shuoming=UploadRequest.Item("shuoming").Item("Value")
shuoming_2=UploadRequest.Item("shuoming_2").Item("Value")
掏出嵌套的dictionary工具的值,注重dictionary的Key辨别巨细写!!!
处置数据库
setconnGraph=server.CreateObject("ADODB.connection")
connGraph.ConnectionString=Application("DNS")
connGraph.Open
SetDB=Server.CreateObject("ADODB.RecordSet")
db.Open"SELECT*FROMt_recordnotewhere11",connGraph,1,3
db.addnew
db("record").appendchunkfilevalue
db("shuoming")=shuoming
db("shuoming_2")=shuoming_2
db("username")=session("username")
db("filetype")=contentType
db("time")=now()
db("filename")=filename
db("filesize")=filesize
db.update
db.close
setdb=nothing
response.write"文件"&filename&"上载乐成"
FunctionStoB(varStr)
str2bin=""
Fori=1ToLen(varstr)
varchar=Mid(varstr,i,1)
varasc=Asc(varchar)
asc对中笔墨符求出来的值大概为正数,
加上65536便可求出它的无标记数值
-1在呆板内是用补码暗示的0xffff,
其无标记值为65535,65535=-1+65536
其他正数顺次类推。
Ifvarasc<0Then
varasc=varasc+65535
EndIf
对中文的处置:把双字节低位和高位分隔
Ifvarasc>255Then
varlow=Left(Hex(Asc(varchar)),2)
varhigh=Right(Hex(Asc(varchar)),2)
str2bin=str2bin&ChrB("&H"&varlow)&ChrB("&H"&varhigh)
Else
str2bin=str2bin&ChrB(AscB(varchar))
EndIf
Next
StoB=str2bin
EndFunction
Bytestringtostringconversion
FunctionBtoS(Binstr)
中笔墨符Skip标记
skipflag=0
strC=""
IfNotIsNull(binstr)Then
lnglen=LenB(binstr)
Fori=1Tolnglen
Ifskipflag=0Then
tmpBin=MidB(binstr,i,1)
判别是不是中文的字符
IfAscB(tmpBin)>127Then
AscW会把二进制的中文双字节字符高位和低位反转,以是要先把中文的上下位反转
strC=strC&Chr(AscW(MidB(binstr,i+1,1)&tmpBin))
skipflag=1
Else
strC=strC&Chr(AscB(tmpBin))
EndIf
Else
skipflag=0
EndIf
Next
EndIf
BtoS=strC
EndFunction
%>
------------------------------
表布局:
------------------------------
dropTABLE[t_RecordNote]
CREATETABLE[t_RecordNote](
[RecordId][int]IDENTITY(1,1)NOTNULL,
[filename][varchar](60)NULL,
[filetype][varchar](40)NULL,
[UserName][varchar](30)NULL,
[Time][datetime]NULL,
[shuoming][varchar](200)NULL,
[shuoming_2][varchar](200)NULL,
[filesize][int]NULL,
[Record][image]NULL,
PRIMARYKEYCLUSTERED
(
[RecordId]
)ON[PRIMARY]
)
GO
强大的可扩展性。ASP具有强大的扩展性,可以实现与多种网络、硬件设备的连接:通过专用的通讯线路远程接入企业;通过远程拨号服务器为远程拨号客户提供服务;通过WAP为移动电话互联网客户服务。 |
|