当前位置:K88软件开发文章中心编程语言AspAsp01 → 文章内容

asp无组件文件上传

减小字体 增大字体 作者:佚名     来源:asp编程网  发布时间:2018-12-30 8:30:35

文件上传组件:upload.asp
<


 
 
Dim 
stream1,stream2,istart,iend,filename
 
 
istart=1
 
 
vbEnter=Chr(13)&

#38
Chr(10) 


function 
getvalue(fstr,foro,paths)&
#39
fstr为接收的名称,foro布尔false为文件上传,true 
为普通字段,path为上传文件存放路径
 
 
 
if 
foro 
then
 
 
 
 
getvalue="
"

 
 
 
 
istart=instring(istart,fstr)

 
 
 
 
istart=istart+len(fstr)+5
 
 
 
 
iend=instring(istart,vbenter+"
-----------------------------"
)
 
 
 
 
if 
istart>
5+len(fstr) 
then
 
 
 
 
getvalue=substring(istart,iend-istart)
 
 
 

 
 
 
 
else
 
 
 
 
getvalue="
"

 
 
 
 
end 
if
 
 
 
 
else
 

 
 
 
 
istart=instring(istart,fstr)
 
 
 
 
istart=istart+len(fstr)+13
 
 
 
 
iend=instring(istart,vbenter)-1
 
 
 
 

 
 
 
 
filename=substring(istart,iend-istart)
 
 
 
 
filename=getfilename(filename)
 
&
#39
CheckFileExt(fstr)&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39
&
#39

 
 
 
 
istart=instring(iend,vbenter+vbenter)+3
 
 
 
 
iend=instring(istart,vbenter+"
-----------------------------"
)
 
 
 
 
filestart=istart
 
 
 
 
filesize=iend-istart-1
 
 
 
 
objstream.position=filestart
 
 
 
 
Set 
sf 

Server.CreateObject("
ADODB.Stream"
)
 
 
 
 
sf.Mode=3 

 
 
 
 
sf.Type=1 

 
 
 
 
sf.Open 

 
 
 
 
objstream.copyto 
sf,FileSize 

 
 
 
 

 
 
 
 
 
if 
filename<
>
"
"
 
then
 
 
 
 
Set 
rf 

Server.CreateObject("
Scripting.FileSystemObject"
)
 
 
 
 
i=0
 
 
 
 
fn=filename
 
 
 
 
while 
rf.FileExists(server.mappath(paths+fn))

 
 
 
 
 
 
fn=cstr(i)+filename
 
 
 
 
 
 
i=i+1
 
 
 
 
 
 
wend
 
 
 
 
filename=fn
 
 
 
 
sf.SaveToFile 
server.mappath(paths+filename),2
 
 
 
 
end 
if
 
 
 
 
getvalue=filename
 
 
 
 
end 
if 
 
 

end 
function

Private 
function 
GetFileName(FullPath) 

 
 
If 
FullPath 
<
>
 
"
"
 
Then 

 
 
 
GetFileName 

mid(FullPath,InStrRev(FullPath, 
"
\"
)+1) 

 
 
Else 

 
 
 
GetFileName 

"
"
 

 
 
End 
If 

End 
 
function 


Function 
inString(theStart,varStr) 

dim 
i,j,bt,theLen,str 

InString=0 

Str=toByte(varStr) 

theLen=LenB(Str) 

for 
i=theStart 
to 
objStream.Size-theLen 

 
 
 
if 
i>
objstream.size 
then 
exit 
Function 

 
 
 

 
 
 
objstream.Position=i-1 

 
 
 
if 
AscB(objstream.Read(1))=AscB(midB(Str,1)) 
then 

 
 
 
 
InString=i 

 
 
 
 
for 
j=2 
to 
theLen 

 
 
 
 
 
 
if 
objstream.EOS 
then 
 

 
 
 
 
 
 
 
 
inString=0 

 
 
 
 
 
 
 
 
Exit 
for 

 
 
 
 
 
 
end 
if 

 
 
 
 
 
 
if 
AscB(objstream.Read(1))<
>
AscB(MidB(Str,j,1)) 
then 

 
 
 
 
 
 
 
 
InString=0 

 
 
 
 
 
 
 
 
Exit 
For 

 
 
 
 
 
 
end 
if 

 
 
 
 
next 

 
 
 
 
if 
InString<
>

then 
Exit 
Function 

 
 
 
end 
if 

next 

End 
Function 



function 
toByte(Str) 

 
 
 
dim 
i,iCode,c,iLow,iHigh 

 
 
 
toByte="
"
 

 
 
 
For 
i=1 
To 
Len(Str) 

 
 
 
c=mid(Str,i,1) 

 
 
 
iCode 
=Asc(c) 

 
 
 
If 
iCode<

Then 
iCode 

iCode 

65535 

 
 
 
If 
iCode>
255 
Then 

 
 
 
 
 
iLow 

Left(Hex(Asc(c)),2) 

 
 
 
 
 
iHigh 
=Right(Hex(Asc(c)),2) 

 
 
 
 
 
toByte 

toByte 
&

#38
 
chrB("
&

#38
H"
&

#38
iLow) 
&

#38
 
chrB("
&

#38
H"
&

#38
iHigh) 

 
 
 
Else 

 
 
 
 
 
toByte 

toByte 
&

#38
 
chrB(AscB(c)) 

 
 
 
End 
If 

 
 
 
Next 

End 
function 


Function 
subString(theStart,theLen) 

dim 
i,c,stemp 

objStream.Position=theStart-1 

stemp="
"
 

for 
i=1 
to 
theLen 

 
 
 
if 
objStream.EOS 
then 
Exit 
for 

 

[1] [2]  下一页


asp无组件文件上传