目前有很多无组件上传类,我大概看了一下,大多写的相当复杂,有的居然还只能传文本
最关键的是没有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>
