使用AspUpload组件上传事例代码

2010-08-28 10:53:29来源:西部e网作者:

‘检查文件类型函数
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="userfiles/"&filename
       filename="../userfiles/"&filename
       file.saveas Server.MapPath(filename)       '上传保存文件
       response.write "文件已成功上传"
       response.write filesm
       'response.write "请复制软件地址到下载地址处:"
        'response.write "<input type=text name=T1 size=50 value="&downname&">"
       Next
   End If
End If
set Upload = nothing
end sub

关键词:ASP

赞助商链接: