無組件上傳常式

來源:互聯網
上載者:User
上傳|無組件 -----------------------------
表單填寫頁的內容:
-----------------------------
<html>
<head>
<meta name="Author" content="Sander Duivestein">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>將本地的檔案上傳到資料庫</title>
</head>
<body>
<font size="2" size="2"><br>
</font>
<form name="frmUpload" method="post" enctype="multipart/form-data" action="Upload.asp">
<table cellspacing="0" cellpadding="0" width="490">
<tr>
<td width="167">
<p align="right"><font size="2" size="2">請選擇檔案:</font></p>
</td>
<td width="319"><font size="2" size="2"><input type="file" name="vFileName"></font></td>
</tr>
<tr>
<td align="right" width="167"><font size="2" size="2">檔案說明1:</font></td>
<td width="319"><input name="shuoming" size="32" ></font></td>
</tr>
<tr>
<td align="right" width="167"><font size="2" size="2">檔案說明2:</font></td>
<td width="319"><input name="shuoming_2" size="32" </td>
</tr>
<td width="167"></td>
<td width="319">
<p align="left"><font size="2" size="1"><input type="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>
<td colspan="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.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 "<hr>"
' response.write "name="&name&"<BR>"
' name為表單項的名字
'Test if object is of file type
If PosFile<>0 AND (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.binarywrite value
' 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為一長串二進位碼
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



相關文章

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。