51网络科技专业提供

香港空间

美国空间

PHP空间

国内免备案空间

月付空间

免备案虚拟主机

,支持试用30天
售前客服
在线咨询
在线咨询
在线咨询
售后服务
在线咨询
在线咨询
财务问题
在线咨询
 
推荐产品
    300M国内免备案空间
    300M网站空间,送60M数据库!
    现价只要:22元/月
    500M国内免备案空间
    500M网站空间,送100M数据库!
    现价只要:29元/月
    1G国内免备案空间
    1G网站空间,送300M数据库!
    现价只要:39元/月
    500M香港免备案空间
    500M网站空间,送160M数据库!
    现价只要:26元/月
    1G香港免备案空间
    1G网站空间,送300M数据库!
    现价只要:36元/月
    100M美国空间
    100M网站空间,送30M数据库!
    现价只要:12.8元/月
 
您的当前位置:首页 > 常见问题 > 建站常见问题 > 正文
如何使用AspUpload组件上传文件
文章来源:51网络科技  点击数:  更新时间:2012/12/20 17:08:43
购买国内免备案空间购买香港空间【不限iis】宽屏网站制作【还送手机网站】
香港云主机/99元/月国内空间【免费备案】 特价网站空间
.Net专用空间网站快速排名 游戏空间【支持月付】
使用AspUpload组件上传文件,使用范例代码如下:

AspUpload组件上传测试
<form method="POST" enctype="multipart/form-data" action="?act=upload">
 <input type="file" size="40" name="file1"><br>
 <!--<input type="file" size="40" name="file2"><br>
 <input type="file" size="40" name="file3"><br>-->
 <br>其他表单项<input type="text" name="uploadText" value=""><br>
 <br><input type="submit" value="上传文件">
</form>
<% 
if request("act") = "upload" then

 AllowExt = "jpg,png,gif,zip,rar,sql,txt,bak"
 On Error Resume Next

 ' 新建AspUpload对象
 Set Upload = Server.CreateObject("Persits.Upload")

 ' 限制文件大小
 Upload.SetMaxSize 4194304, True

 ' 上传路径--当前目录下的test目录
 uploadDir = Server.MapPath("test")

 ' 尝试创建路径文件夹,true表示忽略目录已存在错误
 Upload.CreateDirectory uploadDir, true

 ' 先上传文件至服务器内存
 Count = Upload.Save()

 ' 检测上传错误
 If Err.Number = 8 Then
  Response.Write chinese2unicode("错误: 文件过大!")
  Response.end
 Else
  If Err <> 0 Then
   response.write chinese2unicode("发生错误:")
   response.write chinese2unicode(Err.Description)
   response.end
  End If
 End If

 'Response.Write chinese2unicode("共 " & Count & " 个文件") & "<br><br>"

 ' 指定一个上传的表单文件
 Set File = Upload.Files("file1")
 If Not File Is Nothing Then
  ' 获取原本文件名
  Filename = File.Filename
  ' 获取文件扩展名
  Fileext = File.Ext

  ' 检测文件格式是否合格
  ChkStr = ","&Lcase(AllowExt)&","
  If Instr(ChkStr,","&right(Fileext,3)&",") <= 0 Then
   Response.Write chinese2unicode("错误: 文件类型不正确!")
   response.write "<br>"
   response.write chinese2unicode("只允许:"&AllowExt)
   ' 删除内存中的临时文件,以释放内存或硬盘空间(还可用Copy、Move两个指令)
   File.Delete
  ' 检测是否存在文件
  elseif Upload.FileExists(uploadDir & "\\" & Filename) Then
   File.SaveAs uploadDir & "\\" & Filename
   Response.Write chinese2unicode("已覆盖存在相同文件名的文件: ") & File.Path
  ' 保存文件
  else
   File.SaveAs uploadDir & "\\" & Filename
   Response.Write chinese2unicode("文件已保存到: ") & File.Path
  end If
 Else
  Response.Write chinese2unicode("错误: 您并没有选择文件!")
 End If

 Response.Write "<br><br>"

 '' 批量上传文件,去掉注释即可用。
 For Each File in Upload.Files
   'File.SaveAs uploadDir & "\\" & File.FileName
   'Response.Write chinese2unicode("文件已保存到: ") & File.Path & "<br>"
 Next


'Response.Write "<br><br>Files:<br>"
For Each File in Upload.Files
 'Response.Write File.Name & "= " & File.Path & " (" & File.Size &" bytes)<br>"
Next

'' 列出其他表单内容(必须执行Upload.Save()后才有效)
For Each Item in Upload.Form
 Response.Write Item.Name & " = " & Item.Value & "<br>"
Next

'列出指定的表单内容
Response.Write "<br>"&chinese2unicode("列出指定内容uploadText:"&Upload.Form("uploadText").value)

 

end if

 

' gb2312转unicode,解决中文乱码问题
function chinese2unicode(Str) 
 dim i 
 dim Str_one 
 dim Str_unicode 
 for i=1 to len(Str) 
  Str_one=Mid(Str,i,1) 
  Str_unicode=Str_unicode&chr(38) 
  Str_unicode=Str_unicode&chr(35) 
  Str_unicode=Str_unicode&chr(120) 
  Str_unicode=Str_unicode& Hex(ascw(Str_one)) 
  Str_unicode=Str_unicode&chr(59) 
 next 
 Response.Write Str_unicode 
end function     
%>

国内、香港、美国、全免备案www.51mianbeian.com--51网络科技,专业免备案空间提供商!
相关文章

上班时间:周一至周六 (9:00-12:00 13:30:00-17:30 19:00-23:00) 地址:中国香港九龙长沙湾长裕街8号
版权所有:51免备案空间 Copyright All Reserved. © 2005-209 WWW.51MIANBEIAN.COM [站点地图] [网站地图] 站长统计
值班客服QQ:1303358280 值班技术QQ:984651771 电子邮箱:idc@51mianbeian.com

免备案空间
51网络科技-专业免备案空间提供商