'================================================ ==========
'Function name: ReSaveRemoteFile
'For use: Find and save the file
'Parameter: Str ---- original string
'Parameter: url ---- Of course, website URL
'Parameter: Dir ----- save directory
'Parameter: InSave ------ whether to save, True, False
'Return value: formatted string
'================================================ ==========
Public Function ReSaveRemoteFile (ByVal str, ByVal URL, ByVal Dir, InSave)
Dim s_Content
Dim re
Dim ContentFile, ContentFileUrl
Dim strTempUrl, strFileUrl, DirTemp, PathTemp, FileTemp, Tempi, TempUrlArray, Arr_Path
Dim sAllowExtName
SAllowExtName = "rm | swf"
S_Content = str
On Error Resume Next
Set re = New RegExp
Re. IgnoreCase = True
Re. Global = True
Re. Pattern = "(src = | href =) (\ S) + [.] {1} (" & sAllowExtName &")))"
Set ContentFile = re. Execute (s_Content)
Dim sContentUrl (), n, I, bRepeat
N = 0
For Each ContentFileUrl In ContentFile
StrFileUrl = Replace (ContentFileUrl. value, "src =", "", 1,-1, 1), "href =", "", 1,-1, 1 ),"'", ""), Chr (34 ),"")
If n = 0 Then
N = n + 1
ReDim sContentUrl (n)
SContentUrl (n) = strFileUrl
Else
BRepeat = False
For I = 1 To UBound (sContentUrl)
If UCase (strFileUrl) = UCase (sContentUrl (I) Then
BRepeat = True
Exit
End If
Next
If bRepeat = False Then
N = n + 1
ReDim Preserve sContentUrl (n)
SContentUrl (n) = strFileUrl
End If
End If
Next
If n = 0 Then
ReSaveRemoteFile = s_Content
Exit Function
End If
For I = 1 To n
StrTempUrl = sContentUrl (I): strTempUrl = FormatRemoteUrl (strTempUrl, URL) 'get the file address
Response. Write (strTempUrl)
IF InSave = True then
Arr_Path = Split (Dir ,"/")
'---------- Create directory -----------------------
For Tempi = 0 To Ubound (Arr_Path)
If Tempi = 0 Then
PathTemp = Arr_Path (0 )&"/"
ElseIf Tempi = Ubound (Arr_Path) Then
Exit
Else
PathTemp = PathTemp & Arr_Path (Tempi )&"/"
End If
If CheckDir (PathTemp) = False Then
If MakeNewsDir (PathTemp) = False Then
SaveTf = False
Exit
End If
End If
Next
'------------------------------------------------------
TempUrlArray = Split (strTempUrl ,"/")
'---------- Check whether the file exists. If the file name exists, change the file name ------------------
Do while True
FileTemp = Dir & MakeRandom (5) & TempUrlArray (Ubound (TempUrlArray) 'generate a random file name
If CheckFile (FileTemp) = False then
Exit Do
End if
Loop
'-------------------------------------------------------------------
Response. Write (FileTemp)
If SaveRemoteFile (FileTemp, strTempUrl) = True then
Response. Write ("saved successfully") & "<Br>"
S_Content = Replace (s_Content, sContentUrl (I), FileTemp, 1,-1, 1) 'Replace the address
Else
Response. Write ("failed to save") & "<Br>"
End if
Else
S_Content = Replace (s_Content, sContentUrl (I), strTempUrl, 1,-1, 1) 'Replace the address
End If
Next
Set re = Nothing
PictureExist = True
ReSaveRemoteFile = s_Content
Exit Function
End Function