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

bywzy 发表于 程序设计 分类,
0

   目前有很多无组件上传类,我大概看了一下,大多写的相当复杂,有的居然还只能传文本
  最关键的是没有10行代码以下的 :)
  我花了一个晚上时间研究了一下ADODB.Stream,并且用了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

« 上一篇: :下一篇 »

没有评论 关于 “ASP实例–6行代码实现无组件上传”

发表我的评论

icon_wink.gif icon_neutral.gif icon_mad.gif icon_twisted.gif icon_smile.gif icon_eek.gif icon_sad.gif icon_rolleyes.gif icon_razz.gif icon_redface.gif icon_surprised.gif icon_mrgreen.gif icon_lol.gif icon_idea.gif icon_biggrin.gif icon_evil.gif icon_cry.gif icon_cool.gif icon_arrow.gif icon_confused.gif icon_question.gif icon_exclaim.gif