目前有很多无组件上传类,我大概看了一下,大多写的相当复杂,有的居然还只能传文本
最关键的是没有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行代码实现无组件上传
bywzy 发表于 程序设计 分类,
25
九月
2006
发表于 2009年10月17日 17:56
好人