欢迎光临
我们一直在努力

远程获取内容,并将内容存在本地电脑上,包括任何文件!利用xmlhttp和adodb.stream,酷!绝对原创!

建站超值云服务器,限时71元/月

<%
————————————————————————
——————-无垠网域:http://www.5inet.net/ ———————
——————-作者:嘻哈呵嘿 ,webmaster@5inet.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:\inetpub\myweb\uploadfile\cache\" & fname,adsavecreateoverwrite
    ——————–将缓冲的内容写入文件————————–
    response.binarywrite objstream.read
    objstream.close()
    set objstream = nothing
    ———————–关闭对象,释放资源————————-
response.write err.description
end sub
%>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 远程获取内容,并将内容存在本地电脑上,包括任何文件!利用xmlhttp和adodb.stream,酷!绝对原创!
分享到: 更多 (0)

相关推荐

  • 暂无文章