欢迎光临
我们一直在努力

ASP中多文件同时上传解决方案

建站超值云服务器,限时71元/月

上传表单如下:

标题:   
性别:
属于:
是否选定:
内容: 分类:          
   选取文件一: 
   选取文件二: 
   选取文件三: 
   选取文件四: 
   选取文件五: 

 

asp源代码:

<html>
<body>
<title>文件上传</title>
<center>
</center>
   <% set obj = server.createobject(“yousoft.uploadfile”)
   response.write “总共上传 ” & obj.count & ” 个文件<br>总数据大小 ” & obj.totalbytes & ” bytes<br>共花费了时间 ” & (obj.spendtime/1000) & ” 秒<br>”
   response.write obj.version %>
<hr>
<table width=”75%” border=”1″>
  <tr>
    <td width=”20%”>标题:</td>
    <td width=”80%”><%=obj.form(“title1”)%></td>
  </tr>
  <tr>
    <td width=”20%”>属于:</td>
    <td width=”80%”><%=obj.form(“sel1”)%></td>
  </tr>
  <tr>
    <td width=”20%”>性别:</td>
    <td width=”80%”><%=obj.form(“sex1”)%></td>
  </tr>
  <tr>
    <td width=”20%”>分类:</td>
    <td width=”80%”><%=obj.form(“list1”)%></td>
  </tr>
  <tr>
    <td width=”20%”>内容: </td>
    <td width=”80%”><%=obj.form(“content1”)%></td>
  </tr>
  <tr>
    <td width=”20%”>是否选定:</td>
    <td width=”80%”><%=obj.form(“select1”)%></td>
  </tr>
  <tr>
    <td width=”20%”>提交按钮:</td>
    <td width=”80%”><%=obj.form(“save”)%></td>
  </tr>
</table>
<p>&nbsp;</p>
<p>上传文件如下:<br>
</p>
<table border=”1″>
  <tr>
    <td nowrap>名称</td>
    <td nowrap>文件名(包括扩展名)</td>
    <td nowrap>文件名(不含扩展名)</td>
    <td nowrap>文件大小(b)</td>
    <td nowrap>原文件路径</td>
    <td nowrap>文件扩展名</td>
    <td nowrap>原文件名(含路径)</td>
  </tr>
  <%for i=0 to obj.count-1 %>
  <% userfile = obj.userfile(i) %>
  <tr>
    <td>
      <% =userfile %>
    </td>
    <td>
      <% =obj.filename(userfile) %>
    </td>
    <td>
      <% =obj.filenamex(userfile) %>
    </td>
    <td>
      <% =obj.filesize(userfile) %>
    </td>
    <td>
      <% =obj.filepath(userfile) %>
    </td>
    <td>
      <% =obj.fileext(userfile) %>
    </td>
    <td>
      <% =obj.oldfilename(userfile)%>
    </td>
  </tr>
  <% obj.savetoftp “192.168.7.168”,21,5000,”xu”,”xu”,0,””,0,””,userfile,obj.filename(userfile) %>
  <% obj.savefile userfile, “c:\” & obj.filename(userfile) %>
  <% obj.savefileas userfile, “c:\” & obj.filename(userfile)  %>
  <% obj.savefileas “file6”, “c:\a.txt”  %>
 <% =obj.getfiledata (userfile,”txt”) %>
  <% next
   set obj=nothing %>
</table>
<hr>
</body>
</html>

上传结果:

总共上传 5 个文件
总数据大小 4317 bytes
共花费了时间 .321 秒
youupload 1.0版 版权所有(c)徐长友


标题: asp中多文件同时上传解决方案
属于: 体育艺术
性别:
分类: 分类3
内容: 在大多数j2ee系统中,我们希望由无状态会话bean形式的工厂或管理器触发适当的事件。但ejb容器创建每一个bean实例的时候都会带有一组重复的监听器。本文告诉你如何在ejb环境中正确实现“观察者”模式。
是否选定:
提交按钮: 确认上传

上传文件如下:

名称 文件名(包括扩展名) 文件名(不含扩展名) 文件大小(b) 原文件路径 文件扩展名 原文件名(含路径)
file1 autoexec.bat autoexec 2 c:\ .bat c:\autoexec.bat
file2 boot.ini boot 199 c:\ .ini c:\boot.ini
file3 config.sys config 2 c:\ .sys c:\config.sys
file4 skin.txt skin 2236 c:\ .txt c:\skin.txt
file5 winntnwstatus.txt winntnwstatus 59 c:\ .txt c:\winntnwstatus.txt

以上使用了youupload上传组件,下面是youupload的介绍:

youupload — 文件上传组件

欢迎使用youupload !

许可协议

请参阅license.txt

功能简介

  • 支持上传多个文件
  • 支持所有格式的文件上传,zip,jpg,gif等格式全部支持
  • 支持将上传的文件改名保存
  • 支持同时使用其它的form input,携带附加的信息,例如,文件说明
  • 支持判断上传文件的大小、文件类型
  • 支持将文件内容保存进数据库
  • 支持上传到ftp目录中
  • 无需iis将目录设置为write(如果是ntfs文件系统,其安全性需要设置,可以简单的设置为everyone full control,或者设置为iusr_server full control)
  • youupload目前无任何功能限制,完全免费使用
  • 适用系统

    适用于 windows 98 + pws4 ,nt4.0 server + iis 4 ,win2k+iis 5

    下载地址

     http://www.csdn.net

    安装指南

    要求: windows nt server 4 edition + sp3 + ie4.01 + option pack / win98 + ie4.01

    1. 如果下载的是安装程序,运行setup即可
    2. 测试,你安装目录下的examples复制到web服务器的发布目录即可测试默认文档default.asp
    3. 在浏览器地址栏输入如 http://yourhost/uploadtest/
    4. 如果上方出现版权所有,基本上没多大问题了
    5. 你再上传一些文件试一下

    组件属性

    • object.form(fieldname)
      返回表单数据

      object.form(“title”) title是表单名称

    • object.savefile(fieldname, filename)
      fieldname:表单名
      filename:新的文件名(注:要包括路径)

      dim upl, filename
      set upl = server.createobject(“yousoft.youupload”)
      filename = upl.filename(“file1”)
      upl.savefile “file1”, “c:\temp\” & filename

    • object.savefileas(fieldname, fname)
      fieldname:表单名
      filename:新的文件名(注:要包括路径)

      dim upl, filename
      set upl = server.createobject(“yousoft.youupload”)
      filename = upl.filename(“file1”)
      upl.savefileas “file1”, “c:\temp\” & filename

    • object.savetoftp(ftp_host,ftp_port,timeout,ftp_user,ftp_password,
      use_proxy,proxy_host,proxy_port,user_dir,fieldname,filename)
      ftp_host :ftp主机(最好用ip地址)
      ftp_port :ftp服务器端口(一般为21)
      timeout :连接ftp超时时间
      ftp_user :ftp登录名
      ftp_password :ftp登录密码
      use_proxy :是否使用代理服务器连接ftp,如果 =1 则使用代理 =0 不使用代理
      proxy_host :代理服务器主机(最好用ip),结合use_proxy使用
      proxy_port :代理服务器端口,结合use_proxy使用
      user_dir :当前ftp路径,为空则表示不指定路径,即登录后默认路径
      fieldname :表单名称,从这决定保存的文件
      filename :指定新的文件名

      obj.savetoftp “192.168.7.168”,21,5000,”xu”,”xu”,0,””,0,””,”file1″,”new.exe”

    • object.filename(fieldname)

    • 得到文件名(包括扩展名)

    • object.filepath((fieldname)
      取得上传文件路径

    • object.filesize((fieldname)
      取得上传文件大小

    • object.fileext(fieldname)
      取得上传文件扩展名

    • object.oldfilename(fieldname)
      取得上传文件完整名(包括路径在内)

    • object.filenamex(fieldname)
      得到文件名(不包括扩展名)

    • object.count
      上传文件数目

    • object.totalbytes
      上传数据总字节数

    • object.spendtime
      上传所花时间(单位:毫秒)

    • object.userfile(n)
      取得上传文件第n个的名称(表单名)

    • object.getfiledata(fieldname,datatype)
      取得上传文件数据
      datatype :
      “bin” 取得二进制数据
      “txt” 取得文本数据

      你可以取得数据存放到数据库中,以文本或二进制方式存放

      <%=obj.getfiledata (“file1″,”txt”) %>

    • object.version
      取得当前youupload版本

     

    使用说明

    请参考examples目录下的示例

    上传form的写法
    <form enctype=”multipart/form-data” method=”post” action=”upload.asp” name=”upload”>
    enctype=”multipart/form-data” 是必须的,并且method必须是post

    如果获得上传文件的文件个数
    set obj=server.createobject(“yousoft.uploadfile”)
    response.write “文件个数:”&obj.count

    如果上传多个文件,如果确定对应file input上传的文件
    obj.userfile(n)
    取得上传文件第n个的名称(表单名)

    如何获得文件的后缀名
    ext=fileext(fieldname) fieldname为表单名,如file1

    如何将文件内容保存进数据库
    如果你使用sql server,需要定义一个image类型的字段
    dim conn,rs
    set conn=server.createobject(“adodb.connection”)
    conn.open “testfile”,”sa”,”xxx”
    set rs=server.createobject(“adodb.recordset”)
    rs.open “select * from [file] where filename is null”,conn,1,3
    rs.addnew
    rs(“filename”)=obj.filename(file1)
    rs(“filesize”)=obj.filesize(file1)
    rs(“filecontent”).appendchunk obj.getfiledata (userfile,”bin”) blob数据不能直接赋值 如果不是二进制保存 “bin” 改为 “txt”
    rs.update
    rs.close
    conn.close
    set rs=nothing
    set conn=nothing   
    相反的要将数据从数据库里面取出来,请参考下面的程序
    dim conn,rs
    dim content
    set conn=server.createobject(“adodb.connection”)
    conn.open “testfile”,”sa”,”xxx”
    set rs=server.createobject(“adodb.recordset”)
    rs.open “select * from [file] where id =” & id,conn,1,1
    content=rs(“filecontent”).getchunk(clng(rs(“filesize”)))))
    conn.close
    set rs=nothing
    set conn=nothing       

    安装可能出现的问题

    如果你发现,请与我联系!

    程序使用可能存在的问题

    如果你发现,请与我联系!

    测试反馈

    如果你在测试中发现任何问题,请mailto: mailto:yousoft@chinaren.com?subject=关于youupload,或者请在我主页的bbs进行讨论或留言。

    希望大家能对这个组件多提意见。

    在我们讨论asp问题的时候,常常会遇到许多问题只有利用asp components来解决,而这些com通常只有在国外的站点才可能找到,可见国内的这方面的东东还少。所以我希望得到各位的支持。

    赞(0)
    版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » ASP中多文件同时上传解决方案
    分享到: 更多 (0)

    相关推荐

    • 暂无文章