1. download the following text file and change. TXT to remote. asp.
Copy codeThe Code is as follows: <%
'Whether to save the remote image when adding a resource
Const sSaveFileSelect = True
'Remote image storage directory. Do not add "/" at the end.
Const sSaveFilePath = "/images/News"
'Remote image storage type
Const sFileExt = "jpg | gif | bmp | png"
'/////////////////////////////////////// //////////////
'Usage: Replace the remote file in the string with a local file and save the remote file.
'Parameter:
'Shtml: string to be replaced
'Ssavepath: Path to save the file
'Sext: the extension to be replaced
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 (RemoteFileurl, "/", "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
'////////////////////////////////////////
'Usage: Save the remote file to the local device.
'Parameter: LocalFileName ------ local file name
'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
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
Set Ads = nothing
End Sub
'////////////////////////////////////////
'Usage: Check whether the component has been installed
'Parameter: strClassString ---- component name
'Return value: True ---- 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. Call method:
<! -- # Include file = "remote. asp" -->
Change the following code to the place where the article is storedCopy codeThe Code is as follows: If sSaveFileSelect = True Then
Rs ("Content") = ReplaceRemoteUrl (ArticleContent, sSaveFilePath, sFileExt)
Else
Rs ("Content") = ArticleContent
End If