ASP implementation of Resaveremotefile function find File Save replacement code _ Application Tips

Source: Internet
Author: User
'================================================
' Function name: resaveremotefile
' Function: Find file Save replace
' Argument: Str----Original string
' Parameters: URL----URL of course site
' Parameters: Dir-----Save Directory
' Parameter: insave------is saved, True,false
' Return value: The string to be formatted
'================================================
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 (replace (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 for
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 file address
Response.Write (Strtempurl)
IF Insave=true Then
Arr_path=split (Dir, "/")
'----------Build a directory-----------------------
For tempi=0 to Ubound (Arr_path)
If tempi=0 Then
Pathtemp=arr_path (0) & "/"
ElseIf Tempi=ubound (Arr_path) Then
Exit for
Else
Pathtemp=pathtemp & Arr_path (tempi) & "/"
End If
If Checkdir (pathtemp) =false Then
If Makenewsdir (pathtemp) =false Then
Savetf=false
Exit for
End If
End If
Next
'------------------------------------------------------
Tempurlarray=split (Strtempurl, "/")
'----------Check if the file exists. If there is a change of file name------------------
Do While True
Filetemp=dir & Makerandom (5) & Tempurlarray (Ubound (Tempurlarray)) ' generates random file names
If checkfile (filetemp) =false Then
Exit do
End If
Loop
'-------------------------------------------------------------------
Response.Write (Filetemp)
If saveremotefile (filetemp,strtempurl) =true Then
Response.Write ("Save Success") & "<Br>"
S_content = replace (S_content,scontenturl (i), filetemp, 1,-1, 1) ' Replace address
Else
Response.Write ("Save Failed") & "<Br>"
End If
Else
S_content = replace (S_content,scontenturl (i), Strtempurl, 1,-1, 1) ' Replace 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.