搜索文章:

首页  |  Java技术  |  Asp.net  |  Asp编程  |  VC/C++  |  Delphi  |  VB编程

ASP实例:6行代码实现无组件上传

strfilename = request.querystring("file1")
  set objstream = server.createobject("adodb.stream")
  objstream.type = 1 adtypebinary
  objstream.open
  objstream.loadfromfile strfilename
  objstream.savetofile server."123_onweb.gif",2

  使用方法:

  把上面的代码写成upload.asp
  在浏览器里面输入:
  http://xxx/upload.asp?file1=c:\上传文件\123.gif
  xxx为你的主机地址
  执行完后你会看到你的目录下面多了一个123_onweb.gif
  他就是你要文件拉!!!!

  根据原理我们可以扩展以下代码:
  upload.asp文件
  <%
  function getfilename(byval strfile)
  if strfile <> "" then
   getfilename = mid(strfile,instrrev(strfile, "\")+1)
  else
   getfilename = ""
  end if
  end  function

  strfilename = request.form("file1")
  set objstream = server.createobject("adodb.stream")
  objstream.type = 1 adtypebinary
  objstream.open
  objstream.loadfromfile strfilename
  objstream.savetofile server.mappath(getfilename(strfilename)),2
  objstream.close
  %>

  upload.htm文件
  <form name="form" action="upload.asp" method="post">
  <input type="submit" name="submit" value="ok">
     <input type="file" name="file1" style="width:400"  value="">
  </form>

()

相关文章:
© 2006   www.java-asp.net