随笔 - 8  文章 - 55  trackbacks - 0
<2015年5月>
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456

常用链接

留言簿(6)

随笔分类

随笔档案

文章分类

文章档案

朋友的Blog

最新评论

阅读排行榜

评论排行榜

 
无组件ASP文件上传源代码 经本人测试通过............

无组件ASP文件上传源代码

动网论坛的无组件上传,
以下是从动网论坛分离出来的代码。

如有更好用的请告诉作者
网名:网海求生者
QQ:54883661
mail:wuyingke5155@163.com

saveannounce_upload.asp 上传页
------------------------------------
<html>
<head>
<style type="text/css">
body {font-size:9pt;}
input {font-size:9pt;}
</style>
<title>文件上传</title>
</head>
<body>
<form name="form" method="post" action="saveannouce_upfile.asp" enctype="multipart/form-data" >
文件
<input type="file" name="file1" size=10>
<input type="submit" name="Submit" value="上传">
</form>
</body>
</html>

------------------------------------
saveannouce_upfile.asp 保存文件到服务器
------------------------------------
<!--#include FILE="upload.inc"-->
<html>
<head>
<title>文件上传</title>
</head>
<body>
<%
dim upload,file,formName,formPath
set upload=new upload_5xSoft ''''建立上传对象
formPath=upload.form("filepath") ''''在目录后加(/)
if right(formPath,1)<>"/" then formPath=formPath&"/"
for each formName in upload.file ''''列出所有上传了的文件
set file=upload.file(formName) ''''生成一个文件对象
if file.filesize<100 then
response.write "<font size=2>请先选择你要上传的文件 [ <a href=# onclick=history.go(-1)>重新上传</a> ]</font>"
response.end
end if
if file.filesize>500*1000 then ''设置上传文件大小为500K
response.write "<font size=2>文件大小超过了限制 500K [ <a href=# onclick=history.go(-1)>重新上传</a> ]</font>"
response.end
end if
if file.FileSize>0 then ''''如果 FileSize > 0 说明有文件数据
file.SaveAs Server.mappath("updata\"&file.FileName) ''''保存文件
end if
set file=nothing
next
set upload=nothing
response.write "<font size=2>文件上传成功 [ <a href=# onclick=history.go(-1)>继续上传</a> ]</font>"
%>
</body>
</html>

未完接下


接上

------------------------------------
upload.inc 建立upload对象
------------------------------------
<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>

dim upfile_5xSoft_Stream

Class upload_5xSoft

dim Form,File,Version

Private Sub Class_Initialize
dim iStart,iFileNameStart,iFileNameEnd,iEnd,vbEnter,iFormStart,iFormEnd,theFile
dim strDiv,mFormName,mFormValue,mFileName,mFileSize,mFilePath,iDivLen,mStr
Version=""
if Request.TotalBytes<1 then Exit Sub
set Form=CreateObject("Scripting.Dictionary")
set File=CreateObject("Scripting.Dictionary")
set upfile_5xSoft_Stream=CreateObject("Adodb.Stream")
upfile_5xSoft_Stream.mode=3
upfile_5xSoft_Stream.type=1
upfile_5xSoft_Stream.open
upfile_5xSoft_Stream.write Request.BinaryRead(Request.TotalBytes)

vbEnter=Chr(13)&Chr(10)
iDivLen=inString(1,vbEnter)+1
strDiv=subString(1,iDivLen)
iFormStart=iDivLen
iFormEnd=inString(iformStart,strDiv)-1
while iFormStart < iFormEnd
iStart=inString(iFormStart,"name=""")
iEnd=inString(iStart+6,"""")
mFormName=subString(iStart+6,iEnd-iStart-6)
iFileNameStart=inString(iEnd+1,"filename=""")
if iFileNameStart>0 and iFileNameStart<iFormEnd then
iFileNameEnd=inString(iFileNameStart+10,"""")
mFileName=subString(iFileNameStart+10,iFileNameEnd-iFileNameStart-10)
iStart=inString(iFileNameEnd+1,vbEnter&vbEnter)
iEnd=inString(iStart+4,vbEnter&strDiv)
if iEnd>iStart then
mFileSize=iEnd-iStart-4
else
mFileSize=0
end if
set theFile=new FileInfo
theFile.FileName=getFileName(mFileName)
theFile.FilePath=getFilePath(mFileName)
theFile.FileSize=mFileSize
theFile.FileStart=iStart+4
theFile.FormName=FormName
file.add mFormName,theFile
else
iStart=inString(iEnd+1,vbEnter&vbEnter)
iEnd=inString(iStart+4,vbEnter&strDiv)

if iEnd>iStart then
mFormValue=subString(iStart+4,iEnd-iStart-4)
else
mFormValue=""
end if
form.Add mFormName,mFormValue
end if

iFormStart=iformEnd+iDivLen
iFormEnd=inString(iformStart,strDiv)-1
wend
End Sub

Private Function subString(theStart,theLen)
dim i,c,stemp
upfile_5xSoft_Stream.Position=theStart-1
stemp=""
for i=1 to theLen
if upfile_5xSoft_Stream.EOS then Exit for
c=ascB(upfile_5xSoft_Stream.Read(1))
If c > 127 Then
if upfile_5xSoft_Stream.EOS then Exit for
stemp=stemp&Chr(AscW(ChrB(AscB(upfile_5xSoft_Stream.Read(1)))&ChrB(c)))
i=i+1
else
stemp=stemp&Chr(c)
End If
Next
subString=stemp
End function

Private Function inString(theStart,varStr)
dim i,j,bt,theLen,str
InString=0
Str=toByte(varStr)
theLen=LenB(Str)
for i=theStart to upfile_5xSoft_Stream.Size-theLen
if i>upfile_5xSoft_Stream.size then exit Function
upfile_5xSoft_Stream.Position=i-1
if AscB(upfile_5xSoft_Stream.Read(1))=AscB(midB(Str,1)) then
InString=i
for j=2 to theLen
if upfile_5xSoft_Stream.EOS then
inString=0
Exit for
end if
if AscB(upfile_5xSoft_Stream.Read(1))<>AscB(MidB(Str,j,1)) then
InString=0
Exit For
end if
next
if InString<>0 then Exit Function
end if
next
End Function

Private Sub Class_Terminate
form.RemoveAll
file.RemoveAll
set form=nothing
set file=nothing
upfile_5xSoft_Stream.close
set upfile_5xSoft_Stream=nothing
End Sub


Private function GetFilePath(FullPath)
If FullPath <> "" Then
GetFilePath = left(FullPath,InStrRev(FullPath, "\"))
Else
GetFilePath = ""
End If
End function

Private function GetFileName(FullPath)
If FullPath <> "" Then
GetFileName = mid(FullPath,InStrRev(FullPath, "\")+1)
Else
GetFileName = ""
End If
End function

Private 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<0 Then iCode = iCode + 65535
If iCode>255 Then
iLow = Left(Hex(Asc(c)),2)
iHigh =Right(Hex(Asc(c)),2)
toByte = toByte & chrB("&H"&iLow) & chrB("&H"&iHigh)
Else
toByte = toByte & chrB(AscB(c))
End If
Next
End function
End Class


Class FileInfo
dim FormName,FileName,FilePath,FileSize,FileStart
Private Sub Class_Initialize
FileName = ""
FilePath = ""
FileSize = 0
FileStart= 0
FormName = ""
End Sub

Public function SaveAs(FullPath)
dim dr,ErrorChar,i
SaveAs=1
if trim(fullpath)="" or FileSize=0 or FileStart=0 or FileName="" then exit function
if FileStart=0 or right(fullpath,1)="/" then exit function
set dr=CreateObject("Adodb.Stream")
dr.Mode=3
dr.Type=1
dr.Open
upfile_5xSoft_Stream.position=FileStart-1
upfile_5xSoft_Stream.copyto dr,FileSize
dr.SaveToFile FullPath,2
dr.Close
set dr=nothing
SaveAs=0
end function
End Class
</SCRIPT>

完.....................
posted on 2006-06-13 15:27 blog搬家了--[www.ialway.com/blog] 阅读(10928) 评论(26)  编辑  收藏 所属分类: PHP

FeedBack:
# re: 无组件ASP文件上传源代码 经本人测试通过............ [转] 2006-09-20 15:11 红红私服发布网
bu hao a   回复  更多评论
  
# re: 无组件ASP文件上传源代码 经本人测试通过............ [转] 2006-10-16 09:07 乞怪猪在学习!
好的.我自己都在用的.  回复  更多评论
  
# re: 无组件ASP文件上传源代码 经本人测试通过............ [转] 2006-10-16 09:07 乞怪猪在学习!
这个东东是动网上的东东.  回复  更多评论
  
# re: 无组件ASP文件上传源代码 经本人测试通过............ [转] 2008-08-19 17:08 fei
帅 上传成功  回复  更多评论
  
# re: 无组件ASP文件上传源代码 经本人测试通过............ [转] 2008-08-27 16:06 11
11  回复  更多评论
  
# re: 无组件ASP文件上传源代码 经本人测试通过............ [转] 2008-09-27 01:06 1123
我的怎么不可以啊 运行后他说我Microsoft VBScript 运行时错误 '800a01fa'

类没有被定义: 'upload_5xSoft'
那位大哥给我解决啊  回复  更多评论
  
# re: 无组件ASP文件上传源代码 经本人测试通过............ [转] 2008-10-25 23:16 机战私服 www.jzsf800.cn
机战私服 www.jzsf800.cn  回复  更多评论
  
# re: 无组件ASP文件上传源代码 经本人测试通过............ [转] 2008-10-25 23:16 www.jzsf800.cn
www.jzsf800.cn  回复  更多评论
  
# re: 无组件ASP文件上传源代码 经本人测试通过............ [转] 2008-11-20 13:26 re
ADODB.Stream 错误 '800a0bbc'

写入文件失败。

/upload.inc,行 175
  回复  更多评论
  
# re: 无组件ASP文件上传源代码 经本人测试通过............ [转][未登录] 2008-12-19 15:17 aa
我也报错
  回复  更多评论
  
# re: 无组件ASP文件上传源代码 经本人测试通过............ [转] 2009-06-15 10:07 网友
呵呵,谢谢,我的也成功了。不成功是因为要在你的目录里面新建一个update文件夹用来保存上传的图片文件
  回复  更多评论
  
# re: 无组件ASP文件上传源代码 经本人测试通过............ [转][未登录] 2009-07-29 12:26 王雷
有这份心...
不错,C回去研究一下...
这个课题我被困扰好久了...  回复  更多评论
  
# re: 无组件ASP文件上传源代码 经本人测试通过............ [转] 2009-07-31 14:35 迷蒙蒙
成功!谢谢!
建一个updata文件夹  回复  更多评论
  
# re: 无组件ASP文件上传源代码 经本人测试通过............ [转] 2009-08-30 14:02 诉讼
成功上传。谢谢!  回复  更多评论
  
# re: 无组件ASP文件上传源代码 经本人测试通过............ [转] 2009-10-07 14:02 stf
上传ok  回复  更多评论
  
# re: 无组件ASP文件上传源代码 经本人测试通过............ [转][未登录] 2009-11-01 10:51 小虎
谢谢楼主哦~~
我今天找得快崩溃了,总算找到了一个好的啦~~

谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢  回复  更多评论
  
# re: 无组件ASP文件上传源代码 经本人测试通过............ [转] 2009-11-02 13:51 冰城
需要建立一个updata的文件夹,而不是update的文件夹,而且还修改文件夹的写入属性。
msn:icycity@163.com  回复  更多评论
  
# re: 无组件ASP文件上传源代码 经本人测试通过............ [转] 2009-11-17 13:31 cooleaf
我的为什么按上述设置了还是不行呢?
1.在C:\Inetpub\wwwroot下建一目录“updata”;
2.在此目录上点右键属性栏里取消只读属性;
3.执行文件上传后报错如下:
错误类型:
ADODB.Stream (0x800A0BBC)
写入文件失败。
/upload.inc, 第 175 行


浏览器类型:
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; CIBA; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)  回复  更多评论
  
# re: 无组件ASP文件上传源代码 经本人测试通过............ [转] 2010-01-11 17:26 sunqiuli
xiexie  回复  更多评论
  
# re: 无组件ASP文件上传源代码 经本人测试通过............ [转] 2013-11-23 13:51 wuyaog
你好,我测试后怎么老是提示:

Microsoft VBScript 运行时错误 '800a01fa'
类没有被定义: 'upload_5xSoft'
\saveannouce_upfile.asp, line 17

是哪出问题了?

  回复  更多评论
  
# re: 无组件ASP文件上传源代码 经本人测试通过............ [转] 2014-05-23 18:20 flybrid123
太好了!!!整整一天了!!  回复  更多评论
  
# re: 无组件ASP文件上传源代码 经本人测试通过............ [转] 2014-10-26 22:46 莎莎
sdfs  回复  更多评论
  
# re: 无组件ASP文件上传源代码 经本人测试通过............ [转] 2014-10-26 22:48 30540562
楼主,我找这个问题很久了,一直没解决好.
我测试后提示:

Microsoft VBScript 运行时错误 '800a01fa'
类没有被定义: 'upload_5xSoft'
\saveannouce_upfile.asp, line 17

是哪出问题了?
  回复  更多评论
  
# re: 无组件ASP文件上传源代码 经本人测试通过............ [转] 2014-11-10 09:11 keven
因为你upload.inc类没有调用正确,upload.inc这个写进去你肯定需要用<%%>将方法包含起来的  回复  更多评论
  
# re: 无组件ASP文件上传源代码 经本人测试通过............ [转] 2014-11-20 19:32 
为什么上传不了,数据库url还乱码
<!--#include file="../conn.asp" -->
<!--#include file="seeion.asp"-->
<!--#include file="../inc/upload.inc"--> /table>
</body>
</html>
<%
if Request.QueryString("act")="ok" then
set rs=server.createobject("adodb.recordset")
sql="select * from download"
rs.open sql,conn,1,3
title=request.form("title")
ly=request.form("ly")
zz=request.form("zz")
body=request.form("body")
url="..\upload\"&Trim(Request.Form("file1"))
'''''
dim upload,file,formName,formPath
set upload=new upload_5xSoft ''''建立上传对象
formPath=upload.form("filepath") ''''在目录后加(/)
if right(formPath,1)<>"/" then formPath=formPath&"/"
for each formName in upload.file ''''列出所有上传了的文件
set file=upload.file(formName) ''''生成一个文件对象


if file.FileSize>0 then ''''如果 FileSize > 0 说明有文件数据
file.SaveAs Server.mappath("..\upload\"&file.FileName) ''''保存文件
end if
set file=nothing
next
set upload=nothing

''''

if title="" then
response.Write("<script language=javascript>alert('下载名称不能为空!');history.go(-1)</script>")
response.end
end if
if url="" then
response.Write("<script language=javascript>alert('下载地址不能为空!');history.go(-1)</script>")
response.end
end if
if body="" then
response.Write("<script language=javascript>alert('内容不能为空!');history.go(-1)</script>")
response.end
end if
rs.addnew
rs("title")=title
rs("ly")=ly
rs("zz")=zz
rs("body")=body
rs("url")=url
rs.update
rs.close
set rs=nothing
conn.close
set rs=nothing
Response.Write "<script>alert('恭喜你,下载资源增加成功,点击继续添加!');window.location.href='add_download.asp';</script>"
end if
%>  回复  更多评论
  
# re: 无组件ASP文件上传源代码 经本人测试通过............ [转][未登录] 2015-05-15 10:52 匿名
An error occurred on the server when processing the URL. Please contact the system administrator.
If you are the system administrator please click here to find out more about this error
出现这个是什么原因?  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: