The ReSaveRemoteFile function uses asp to find the code for saving and replacing files

Source: Internet
Author: User

'================================================ ==========
'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

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.