|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
asp对于服务器的要求较高,一般的服务器如果访问量一大就垮了,不得不重启。getfile.htm
-------------------------
<html>
<head>
<title>保留图片到数据库</title>
</head>
<body>
<b>
<p></b>你能够找个图片尝尝,保留终了后会有提醒</p>
<formMETHOD="POST"ENCTYPE="multipart/form-data"ACTION="savetodb.asp">
<p>Email:<inputNAME="email"VALUE="wangcq@sina.com"size="20"><br>
Picture:<inputTYPE="file"NAME="blob"><br>
<inputTYPE="submit"NAME="Enter"></p>
</form>
</body>
</html>
savetodb.asp
----------------------------------
<%
Response.Buffer=TRUE
Response.Clear
byteCount=Request.TotalBytes
RequestBin=Request.BinaryRead(byteCount)
DimUploadRequest
SetUploadRequest=CreateObject("Scripting.Dictionary")
BuildUploadRequestRequestBin
email=UploadRequest.Item("email").Item("Value")
contentType=UploadRequest.Item("blob").Item("ContentType")
filepathname=UploadRequest.Item("blob").Item("FileName")
filename=Right(filepathname,Len(filepathname)-InstrRev(filepathname,""))
picture=UploadRequest.Item("blob").Item("Value")
Response.ContentType=contentType
Response.binaryWritepicture
setobjCn=server.createobject("adodb.connection")
setobjRst=server.createobject("adodb.recordset")
objCn.Open"upload"
objrst.Open"pic",objcn,1,3,2
objrst.addnew
objrst.fields("filename")=filename
objrst.fields("type")="gif"
objrst.fields("what").appendchunkpicture
objrst.update
response.write"<ahref=showpic.asp?id="&objrst("id")&">第"&objrst("id")&"个图片。</a>"
objrst.close
objCn.close
setobjrst=nothing
setobjcn=nothing
%>
<!--#includefile="upload.asp"-->
showpic.asp
----------------------------------------
<%
setobjCn=server.createobject("adodb.connection")
setobjRst=server.createobject("adodb.recordset")
objCn.Open"upload"
objrst.Open"selectwhatfrompicwhereid="&request("id"),objcn
ifnotobjrst.eofthen
response.binarywriteobjrst("what")
endif
objrst.close
objCn.close
setobjrst=nothing
setobjcn=nothing
%>
upload.asp
-------------------------------------------
<%
SubBuildUploadRequest(RequestBin)
Gettheboundary
PosBeg=1
PosEnd=InstrB(PosBeg,RequestBin,getByteString(chr(13)))
boundary=MidB(RequestBin,PosBeg,PosEnd-PosBeg)
boundaryPos=InstrB(1,RequestBin,boundary)
Getalldatainsidetheboundaries
Dountil(boundaryPos=InstrB(RequestBin,boundary&getByteString("--")))
Membersvariableofobjectsareputinadictionaryobject
DimUploadControl
SetUploadControl=CreateObject("Scripting.Dictionary")
Getanobjectname
Pos=InstrB(BoundaryPos,RequestBin,getByteString("Content-Disposition"))
Pos=InstrB(Pos,RequestBin,getByteString("name="))
PosBeg=Pos+6
PosEnd=InstrB(PosBeg,RequestBin,getByteString(chr(34)))
Name=getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
PosFile=InstrB(BoundaryPos,RequestBin,getByteString("filename="))
PosBound=InstrB(PosEnd,RequestBin,boundary)
Testifobjectisoffiletype
IfPosFile0AND(PosFile<PosBound)Then
GetFilename,content-typeandcontentoffile
PosBeg=PosFile+10
PosEnd=InstrB(PosBeg,RequestBin,getByteString(chr(34)))
FileName=getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
Addfilenametodictionaryobject
UploadControl.Add"FileName",FileName
Pos=InstrB(PosEnd,RequestBin,getByteString("Content-Type:"))
PosBeg=Pos+14
PosEnd=InstrB(PosBeg,RequestBin,getByteString(chr(13)))
Addcontent-typetodictionaryobject
ContentType=getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
UploadControl.Add"ContentType",ContentType
Getcontentofobject
PosBeg=PosEnd+4
PosEnd=InstrB(PosBeg,RequestBin,boundary)-2
Value=MidB(RequestBin,PosBeg,PosEnd-PosBeg)
Else
Getcontentofobject
Pos=InstrB(Pos,RequestBin,getByteString(chr(13)))
PosBeg=Pos+4
PosEnd=InstrB(PosBeg,RequestBin,boundary)-2
Value=getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
EndIf
Addcontenttodictionaryobject
UploadControl.Add"Value",Value
Adddictionaryobjecttomaindictionary
UploadRequest.Addname,UploadControl
Looptonextobject
BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)
Loop
EndSub
Stringtobytestringconversion
FunctiongetByteString(StringStr)
Fori=1toLen(StringStr)
char=Mid(StringStr,i,1)
getByteString=getByteString&chrB(AscB(char))
Next
EndFunction
Bytestringtostringconversion
FunctiongetString(StringBin)
getString=""
ForintCount=1toLenB(StringBin)
getString=getString&chr(AscB(MidB(StringBin,intCount,1)))
Next
EndFunction
%>
test.mdb(dsn称号:upload)
----------------------------------------
表pic:
id:主动加
filename:文本
type:文本
what:ole
-----------------------------------------
存成单个文件,放在一个目次下,翻开(必需用http://...)getfile.htm
上传一个.gif或.jpg就能够显现了。
关于年夜文件在显现程序(showpic.asp)中大概会用到轮回和getchunk办法。本人往做。记着,因为ASP今朝临时不撑持二举行制读写,只能存二进制到数据库中。
使用cdonts,可以发送、查看邮件,实现webmail的功能。结合wsh,可以实现对nt主机的管理,如nt用户管理、iis虚拟主机设置、exchange邮箱设置等等,就像管理本地机一样方便。 |
|