您所在的位置:小祥子 » 编程 » ASP » 正文

AspUpload上传文件示例代码

时间:2015-01-23 编辑:佚名 来源:互联网

这是一个组件的使用代码,首先必须得装ASPUPLOAD组件才可以。

代码如下

<% 'AspUpload组件上传文件实例
'检查上传的文件类型
Private CheckFileExt (fileEXT)
dim filetype
filetype="asp,asa,aspx"
filetype=split(filetype,",")
    for i=0 to ubound(filetype)
           if lcase(fileEXT)=lcase(trim(filetype(i))) then
                  CheckFileExt=false
                  exit
           else
                  CheckFileExt=true
           end if
    next
End
'上传函数开始
sub upload_2()
dim Count
on error resume next
Set Upload = Server.CreateObject("Persits.Upload")
Upload.OverwriteFiles = false   '不允许覆盖重名文件
Upload.IgnoreNoPost = True
Upload.SetMaxSize 1048576, True        '文件大小限制
Count = Upload.Save
If Err.Number = 8 Then
   Response.Write "不好意思哦,文件太大了,小于10M) [ <a href=# =history.go(-1)>点这里重新上传吧</a> ]"
Else
   If Err <> 0 Then
      Response.Write "错误信息: " & Err.Deion
   Else
      If Count < 1 Then
      Response.Write "请选择文件 [ <a href=# =history.go(-1)>重新上传</a> ]"
      set Upload =nothing
      exit sub
      End If
       For Each file in Upload.Files '列出将要上传的文件
       fileExt=lcase(replace(File.ext,".",""))
       '判断文件类型
       if CheckFileExt(fileEXT)=false then
       set upload = nothing
       response.write "不能上传asp和asa后缀的文件 [ <a href=# =history.go(-1)>重新上传</a> ]"
       exit sub
       end if
       randomize
       ranNum=int(90000*rnd)+10000
       filename=user&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&File.ext
        downname="uploads/"&filename
       filename="../uploads/"&filename
       file.saveas Server.MapPath(filename) '上传保存文件
       response.write "文件上传成功!"
       response.write filesm
       Next
   End If
End If
set Upload = nothing
end sub
%>

关键词:Asp Upload 上传 文件