1, the following text file download, and will. TXT changed to remote.asp, there is a specific set of methods
Copy Code code as follows:
<%
' Save remote pictures when adding resources
Const Ssavefileselect=true
' Remote picture save directory, end please do not add '/'
Const ssavefilepath= "/images/news"
' Remote picture Save type
Const sfileext= "Jpg|gif|bmp|png"
'/////////////////////////////////////////////////////
' Function: Replace the remote file in the string as a local file and save the remote file
Parameters
' SHTML: string to replace
' Ssavepath: Path to save file
' SEXT: The extension that performs the substitution
Function Replaceremoteurl (SHTML, Ssavefilepath, Sfileext)
Dim s_content
S_content = SHTML
If isobjinstalled ("microsoft.xmlhttp") = False Then
Replaceremoteurl = S_content
Exit Function
End If
Dim Re, remotefile, remotefileurl,savefilename,savefiletype,arrsavefilenames,arrsavefilename,ssavefilepaths
Set re = new REGEXP
Re. IgnoreCase = True
Re. Global = True
Re. Pattern = "((HTTP|HTTPS|FTP|RTSP|MMS):(\/\/|\\\\) {1} ((\w) +[.]) {1,} (net|com|cn|org|cc|tv| [0-9] {1,3}) (\s*\/) ((\s) +[.] {1} ("& Sfileext &")) "
Set remotefile = Re. Execute (s_content)
For each remotefileurl in RemoteFile
Savefiletype = replace (replace (Remotefileurl, "/", "a"), ":", "a")
Arrsavefilename = Right (savefiletype,12)
Ssavefilepaths=ssavefilepath & "/"
Savefilename = ssavefilepaths & Arrsavefilename
Call Saveremotefile (Savefilename, Remotefileurl)
S_content = Replace (s_content,remotefileurl,savefilename)
Next
Replaceremoteurl = S_content
End Function
'////////////////////////////////////////
' Function: Save remote files to local
' Parameter: localfilename------local filename
' remotefileurl------remote file URL
' Return value: True----Successful
' False----failed
Sub Saveremotefile (S_localfilename,s_remotefileurl)
Dim Ads, retrieval, Getremotedata
On Error Resume Next
Set retrieval = Server.CreateObject ("Microsoft.XMLHTTP")
With retrieval
. Open "Get", S_remotefileurl, False, "", ""
. Send
Getremotedata =. Responsebody
End With
Set retrieval = Nothing
Set Ads = Server.CreateObject ("ADODB.stream")
With Ads
. Type = 1
. Open
. Write Getremotedata
. SaveToFile Server.MapPath (s_localfilename), 2
. Cancel ()
. Close ()
End With
Set ads=nothing
End Sub
'////////////////////////////////////////
' Function: Check if the component is installed
' parameter: strclassstring----Component Name
' Return value: True----already installed
' False----not installed
Function isobjinstalled (s_classstring)
On Error Resume Next
isobjinstalled = False
ERR = 0
Dim Xtestobj
Set xtestobj = Server.CreateObject (s_classstring)
If 0 = Err Then isobjinstalled = True
Set xtestobj = Nothing
ERR = 0
End Function
%>
2. Calling method:
<!--#include file= "remote.asp"-->
The place where the article is stored is changed to the following code
Copy Code code as follows:
If ssavefileselect=true Then
Rs ("Content") =replaceremoteurl (Articlecontent,ssavefilepath,sfileext)
Else
Rs ("Content") =articlecontent
End If