<%
'------------------------------------------------------------------------
'-------------------无垠网域:http://www.5.net.net/ ---------------------
'-------------------作者:嘻哈呵嘿 ,webmaster@5.net.net -----------------
'----------远程获取内容,并将内容存在本地电脑上,包括任何文件!----------
'---------------利用xmlhttp和adodb.stream,酷!绝对原创!-----------------
'on error resume next
'set the content type to the specific type that you are sending.
'response.contenttype = "image/jpeg"
'-------------------------------定义输出格式-----------------------------
path=request.querystring("p")
spath = path
if left(lcase(path),7) <> "http://" then
'-------------如果前面没有http就是本地文件,交给localfile处理------------
localfile(path)
else
'--------------------否则为远程文件,交给remotefile处理------------------
remotefile(path)
end if
'response.write err.description
sub localfile(path)
'-------------------如果为本地文件则简单的跳转到该页面-------------------
response.redirect path
end sub
sub remotefile(spath)
'-------------------------处理远程文件函数------------------------------
filename = getfilename(spath)
'-------------getfilename为把地址转换为合格的文件名过程-------------
filename = server.mappath("/uploadfile/cache/" & filename)
set objfso = server.createobject("scripting.filesystemobject")
'response.write filename
if objfso.fileexists(filename) then
'--------------检查文件是否是已经访问过,如是,则简单跳转------------
response.redirect "/uploadfile/cache/" & getfilename(path)
else
'----------------否则的话就先用getbody函数读取----------------------
'response.write path
t = getbody(path)
'-----------------用二进制方法写到浏览器上--------------------------
response.binarywrite t
response.flush
'-----------------输出缓冲------------------------------------------
savefile t,getfilename(path)
'------------------将文件内容缓存到本地路径,以待下次访问-----------
end if
set objfso = nothing
end sub
function getbody(url)
'-----------------------本函数为远程获取内容的函数---------------------
'on error resume next
'response.write url
set retrieval = createobject("microsoft.xmlhttp")
'----------------------建立xmlhttp对象-----------------------------
with retrieval
.open "get", url, false, "", ""
'------------------用get,异步的方法发送-----------------------
.send
'getbody = .responsetext
getbody = .responsebody
'------------------函数返回获取的内容--------------------------
end with
set retrieval = nothing
'response.write err.description
end function
function getfilename(str)
'-------------------------本函数为合格化的文件名函数-------------------
str = replace(lcase(str),"http://","")
str = replace(lcase(str),"//","/")
str = replace(str,"/","")
str = replace(str,vbcrlf,"")
getfilename = str
end function
sub savefile(str,fname)
'-------------------------本函数为将流内容存盘的函数-------------------
'on error resume next
set objstream = server.createobject("adodb.stream")
'--------------建立adodb.stream对象,必须要ado 2.5以上版本---------
objstream.type = adtypebinary
'-------------以二进制模式打开-------------------------------------
objstream.open
objstream.write str
'--------------------将字符串内容写入缓冲--------------------------
'response.write fname
objstream.savetofile "c:\.netpub\myweb\uploadfile\cache\" & fname,adsavecreateoverwrite
'--------------------将缓冲的内容写入文件--------------------------
'response.binarywrite objstream.read
objstream.close()
set objstream = nothing
'-----------------------关闭对象,释放资源-------------------------
'response.write err.description
end sub
%>
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器