上傳|無組件 ASP 無組件上傳
說明:從網上收集了一部分,自己寫了一部分。主要提升就是對於form的位元據進行了類封裝,可以容易的得到form內的元素的資訊。
Form 位元據格式:
分割標誌資料 + 0x0D0A
元素說明資訊 + 0x0D0A0D0A
元素內容資料 + 0x0D0A
分割標誌資料 + 0x0D0A
元素說明資訊 + 0x0D0A0D0A
元素內容資料 + 0x0D0A
……
分割標誌資料 + 0x0D0A
1. Upload.htm
<html>
<head><title>檔案上傳</title></head>
<body>
<form enctype="multipart/form-data" action="upload.asp" method="post">
<input name="text0" type=text value="文字框"><br>
<input name="file1" type=file accept="image/*"><br>
<input name="file2" type=file accept="image/*"><br>
<input type=submit value="上傳">
</form>
</body>
</html>
2. upload.asp
<!--#include file="upload.inc"-->
<%
'by sam 2004,6
'###############################################################################
response.expires = 0
if request.servervariables("REQUEST_METHOD")="POST" then
response.clear()
response.buffer=true
set uform = new uploadform
uform.find_element "text0"
data = midb(uform.formdata,uform.datastart,uform.datalen)
Response.binaryWrite data
sdata = binarytostring(data)
Response.write sdata
Response.binarywrite stringtobinary(sdata)
uform.find_element "file1"
savefile server.mappath("/recv1.dat"),uform.formdata,uform.datastart,uform.datalen
uform.find_element "file2"
savefile server.mappath("/recv2.dat"),uform.formdata,uform.datastart,uform.datalen
set uform = nothing
end if
%>
3. upload.inc
<%
'by sam 2004,6
'#################################################################
function savefile(filename,formdata,start,len)
set strm1=server.createobject("adodb.stream")
set strm2=server.createobject("adodb.stream")
strm1.open
strm1.type=1 'binary
strm2.open
strm2.type=1 'binary
strm1.write formdata
'strm1.savetofile server.mappath("/1.raw"),2
strm1.position = start - 1
strm1.copyto strm2,len
'strm2.savetofile server.mappath("/1.gif"),2
strm2.savetofile filename,2
set strm1=nothing
set strm2=nothing
end function
function simplebinarytostring(binary)
dim i, s
for i = 1 to lenb(binary)
s = s & chr(ascb(midb(binary,i,1)))
next
simplebinarytostring = s
end function
function binarytostring(binary)
dim cl1,cl2,cl3,pl1,pl2,pl3
dim l
cl1 = 1
cl2 = 1
cl3 = 1
l = lenb(binary)
do while cl1<=l
pl3 = pl3 & chr(ascb(midb(binary,cl1,1)))
cl1 = cl1 + 1
cl3 = cl3 + 1
if cl3>300 then
pl2 = pl2 & pl3
pl3 = ""
cl3 = 1
cl2 = cl2 + 1
if cl2>200 then
pl1 = pl1 & pl2
pl2 = ""
cl2 = 1
end if
end if
loop
binarytostring = pl1 & pl2 & pl3
end function