v
详细信息:
-----------------------------
表单填写页的内容:
-----------------------------
将本地的文件上载到数据库
----------------------------------
Upload.asp的内容:
----------------------------------
Response.Buffer = TRUE
Response.Clear
byteCount = Request.TotalBytes
RequestBin = Request.BinaryRead(byteCount)
'response.binarywrite requestbin
'取得表单的全部内容
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim UploadRequest
Set UploadRequest = 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)
Do until (boundaryPos=InstrB(RequestBin,boundary & StoB("--")))
'Members variable of objects are put in a dictionary object
Dim UploadControl
Set UploadControl = CreateObject("Scripting.Dictionary")
'Get an object name
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 "
"
' response.write "name="&name&"
"
' name为表单项的名字
'Test if object is of file type
If PosFile<>0 AND (PosFilePosBeg = PosFile + 10
PosEnd = InstrB(PosBeg,RequestBin,StoB(chr(34)))
FileName = BtoS(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
' response.write "
"
' response.write "filename="&filename&"
"
' 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&"
"
' response.write "
"
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.binarywrite value
' response.write "
"
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&"
"
' value为表单项的值,如果为文件项,则value为一长串二进制码
End If
UploadControl.Add "Value" , Value
UploadRequest.Add name, 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区分大小写!!!
''''''''''''处理数据库'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
set connGraph = server.CreateObject("ADODB.connection")
connGraph.ConnectionString = Application("DNS")
connGraph.Open
Set DB = Server.CreateObject("ADODB.RecordSet")
db.Open "SELECT * FROM t_recordnote where 1<>1",connGraph,1,3
db.addnew
db("record").appendchunk filevalue
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
set db = nothing
response.write "文件"&filename&"上载成功"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function StoB(varStr)
str2bin = ""
For i = 1 To Len(varstr)
varchar = Mid(varstr, i, 1)
varasc = Asc(varchar)
' asc对中文字符求出来的值可能为负数,
' 加上65536就可求出它的无符号数值
' -1在机器内是用补码表示的0xffff,
' 其无符号值为65535,65535=-1+65536
' 其他负数依次类推。
If varasc < 0 Then
varasc = varasc + 65535
End If
'对中文的处理:把双字节低位和高位分开
If varasc > 255 Then
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))
End If
Next
StoB = str2bin
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''
'Byte string to string conversion
Function BtoS(Binstr)
'中文字符Skip标志
skipflag = 0
strC = ""
If Not IsNull(binstr) Then
lnglen = LenB(binstr)
For i = 1 To lnglen
If skipflag = 0 Then
tmpBin = MidB(binstr, i, 1)
'判断是否中文的字符
If AscB(tmpBin) > 127 Then
'AscW会把二进制的中文双字节字符高位和低位反转,所以要先把中文的高低位反转
strC = strC & Chr(AscW(MidB(binstr, i + 1, 1) & tmpBin))
skipflag = 1
Else
strC = strC & Chr(AscB(tmpBin))
End If
Else
skipflag = 0
End If
Next
End If
BtoS = strC
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
%>
------------------------------
表结构:
------------------------------
drop TABLE [t_RecordNote]
CREATE TABLE [t_RecordNote] (
[RecordId] [int] IDENTITY (1, 1) NOT NULL ,
[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 ,
PRIMARY KEY CLUSTERED
(
[RecordId]
) ON [PRIMARY]
)
GO
-----------------------------
表单填写页的内容:
-----------------------------
将本地的文件上载到数据库
请选择文件: | |
文件说明1: | |
文件说明2: |
----------------------------------
Upload.asp的内容:
----------------------------------
Response.Buffer = TRUE
Response.Clear
byteCount = Request.TotalBytes
RequestBin = Request.BinaryRead(byteCount)
'response.binarywrite requestbin
'取得表单的全部内容
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim UploadRequest
Set UploadRequest = 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)
Do until (boundaryPos=InstrB(RequestBin,boundary & StoB("--")))
'Members variable of objects are put in a dictionary object
Dim UploadControl
Set UploadControl = CreateObject("Scripting.Dictionary")
'Get an object name
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 "
"
' response.write "name="&name&"
"
' name为表单项的名字
'Test if object is of file type
If PosFile<>0 AND (PosFilePosBeg = PosFile + 10
PosEnd = InstrB(PosBeg,RequestBin,StoB(chr(34)))
FileName = BtoS(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
' response.write "
"
' response.write "filename="&filename&"
"
' 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&"
"
' response.write "
"
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.binarywrite value
' response.write "
"
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&"
"
' value为表单项的值,如果为文件项,则value为一长串二进制码
End If
UploadControl.Add "Value" , Value
UploadRequest.Add name, 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区分大小写!!!
''''''''''''处理数据库'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
set connGraph = server.CreateObject("ADODB.connection")
connGraph.ConnectionString = Application("DNS")
connGraph.Open
Set DB = Server.CreateObject("ADODB.RecordSet")
db.Open "SELECT * FROM t_recordnote where 1<>1",connGraph,1,3
db.addnew
db("record").appendchunk filevalue
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
set db = nothing
response.write "文件"&filename&"上载成功"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function StoB(varStr)
str2bin = ""
For i = 1 To Len(varstr)
varchar = Mid(varstr, i, 1)
varasc = Asc(varchar)
' asc对中文字符求出来的值可能为负数,
' 加上65536就可求出它的无符号数值
' -1在机器内是用补码表示的0xffff,
' 其无符号值为65535,65535=-1+65536
' 其他负数依次类推。
If varasc < 0 Then
varasc = varasc + 65535
End If
'对中文的处理:把双字节低位和高位分开
If varasc > 255 Then
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))
End If
Next
StoB = str2bin
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''
'Byte string to string conversion
Function BtoS(Binstr)
'中文字符Skip标志
skipflag = 0
strC = ""
If Not IsNull(binstr) Then
lnglen = LenB(binstr)
For i = 1 To lnglen
If skipflag = 0 Then
tmpBin = MidB(binstr, i, 1)
'判断是否中文的字符
If AscB(tmpBin) > 127 Then
'AscW会把二进制的中文双字节字符高位和低位反转,所以要先把中文的高低位反转
strC = strC & Chr(AscW(MidB(binstr, i + 1, 1) & tmpBin))
skipflag = 1
Else
strC = strC & Chr(AscB(tmpBin))
End If
Else
skipflag = 0
End If
Next
End If
BtoS = strC
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
%>
------------------------------
表结构:
------------------------------
drop TABLE [t_RecordNote]
CREATE TABLE [t_RecordNote] (
[RecordId] [int] IDENTITY (1, 1) NOT NULL ,
[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 ,
PRIMARY KEY CLUSTERED
(
[RecordId]
) ON [PRIMARY]
)
GO
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7178747/viewspace-161821/,如需转载,请注明出处,否则将追究法律责任。
上一篇:
ASP进阶之文章在线管理更新(八)(转)
下一篇:
ASP值多少钱,还能值钱多久(转)

请登录后发表评论
登录
全部评论
<%=items[i].createtime%>
<%=items[i].content%>
<%if(items[i].items.items.length) { %>
<%for(var j=0;j
<%}%> <%if(items[i].items.total > 5) { %>
<%}%> <%}%>
<%=items[i].items.items[j].createtime%>
<%=items[i].items.items[j].username%> 回复 <%=items[i].items.items[j].tousername%>: <%=items[i].items.items[j].content%>
还有<%=items[i].items.total-5%>条评论
) data-count=1 data-flag=true>点击查看
<%}%>
转载于:http://blog.itpub.net/7178747/viewspace-161821/