Get content remotely and place the content on the local computer, including any files! Use XMLHTTP and ADODB.stream, cool! Absolutely original!

Source: Internet
Author: User
ado|stream|xml| Original <%
'------------------------------------------------------------------------
'-------------------boundless domain: http://www.5inet.net/---------------------
'-------------------Author: Hip Hop Hey, webmaster@5inet.net-----------------
'----------get content remotely and have the content on the local computer, including any files! ----------
'---------------use XMLHTTP and adodb.stream, cool! Absolutely original! -----------------
' On Error Resume Next
' Set ' the content type to the specific type of you are sending.
' Response.ContentType = ' image/jpeg '
'-------------------------------defines the output format-----------------------------

Path=request.querystring ("P")
spath = Path
If left (LCase (path), 7) <> "http://" then
'-------------if HTTP is not in front of the local file, give LocalFile processing------------
LocalFile (PATH)
Else
'--------------------Otherwise for remote files, to RemoteFile processing------------------
RemoteFile (Path)
End If
' Response.Write Err. Description

Sub LocalFile (Path)
'-------------------simply jump to the page if it is a local file-------------------
Response.Redirect Path
End Sub

Sub RemoteFile (spath)
'-------------------------processing remote file Functions------------------------------
FileName = GetFileName (spath)
'-------------GetFileName the process of converting addresses to qualified file names-------------
filename = Server.MapPath ("/uploadfile/cache/" & filename)
Set objFSO = Server.CreateObject ("Scripting.FileSystemObject")
' Response.Write FileName
If Objfso.fileexists (FileName) Then
'--------------Check to see if the file is already visited, and if so, simply jump------------
Response.Redirect "/uploadfile/cache/" & GetFileName (Path)
Else
'----------------Otherwise, read the GetBody function First----------------------
' Response.Write Path
t = GetBody (Path)
'-----------------is written to the browser using the binary method--------------------------
Response.BinaryWrite T
Response.Flush
'-----------------Output buffer------------------------------------------
SaveFile T,getfilename (PATH)
'------------------cache the contents of the file to the local path for the next visit-----------
End If
Set objFSO = Nothing
End Sub

Function getbody (URL)
'-----------------------function for remote fetch of content---------------------
' On Error Resume Next
' Response.Write URL
Set retrieval = CreateObject ("Microsoft.XMLHTTP")
'----------------------set up the XMLHTTP object-----------------------------
With retrieval
. Open "Get", url, False, "", ""
'------------------send-----------------------with Get, asynchronous method
. Send
' GetBody =. ResponseText
GetBody =. Responsebody
'------------------function returns the contents of the Fetch--------------------------
End With
Set retrieval = Nothing
' Response. Write Err. Description
End Function

Function GetFileName (str)
'-------------------------This function is a qualified filename function-------------------
str = Replace (LCase (str), "http://", "")
str = Replace (LCase (str), "//", "/")
str = Replace (str, "/", "")
str = replace (STR,VBCRLF, "")
GetFileName = str
End Function

Sub SaveFile (Str,fname)
'-------------------------this function to save the contents of the stream-------------------
' On Error Resume Next
Set objstream = Server.CreateObject ("ADODB. Stream ")
'--------------set up the ADODB.stream object, you must have more than ADO 2.5 version---------
objStream.Type = adTypeBinary
'-------------open in binary mode-------------------------------------
objStream.Open
Objstream.write Str
&nb



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.