Replacesaveremotefile to replace, save the remote picture code _ Application Tips

Source: Internet
Author: User
'==================================================
' Function name: replacesaveremotefile
' Function: Replace, save remote picture
' Parameter: constr------The string to replace
' Parameter: SAVETF------Whether to save the file, False not save, true save
' Parameter: Tisturl------Current page address
'==================================================
Function Replacesaveremotefile (Constr,strinstalldir,strchanneldir,savetf,tisturl)
If constr= "$False $" or constr= "" or strchanneldir= "" Then
Replacesaveremotefile=constr
Exit Function
End If
Dim Tempstr,tempstr2,tempstr3,re,matches,match,tempi,temparray,temparray2

Set Re = New Regexp
Re.ignorecase = True
Re.global = True
Re.pattern = "]> "
Set matches =re.execute (CONSTR)
For the Match in matches
If tempstr<> "" Then
Tempstr=tempstr & "$Array $" & Match.value
Else
Tempstr=match.value
End If
Next
If tempstr<> "" Then
Temparray=split (TempStr, "$Array $")
Tempstr= ""
For tempi=0 to Ubound (Temparray)
Re.pattern = "src\s*=\s*.+?\." (Gif|jpg|bmp|jpeg|psd|png|svg|dxf|wmf|tiff) "
Set matches =re.execute (Temparray (tempi))
For the Match in matches
If tempstr<> "" Then
Tempstr=tempstr & "$Array $" & Match.value
Else
Tempstr=match.value
End If
Next
Next
End If
If tempstr<> "" Then
Includepic=1 ' Photo News
Re.pattern = "src\s*=\s*"
Tempstr=re.replace (TempStr, "")
End If
Set matches=nothing
Set re=nothing
If tempstr= "" or IsNull (TEMPSTR) =true Then
Replacesaveremotefile=constr
Exit function
End If
Tempstr=replace (TempStr, "" "", "")
Tempstr=replace (TempStr, "'", "")
Tempstr=replace (TempStr, "", "")

Dim Remotefileurl,savepath,pathtemp,dtnow,strfilename,strfiletype,arrsavefilename,rannum,arr_path
Dtnow=now ()
If Savetf=true Then
'***********************************
Savepath= Strchanneldir & Year (Dtnow) & Right ("0" & Month (Dtnow), 2) & "/"
Response.Write "Link path:" & Savepath & "<br>"
Arr_path=split (Savepath, "/")
Pathtemp= ""
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
End If

' Get rid of duplicate pictures.
Temparray=split (TempStr, "$Array $")
Tempstr= ""
For tempi=0 to Ubound (Temparray)
If Instr (Lcase (TEMPSTR), Lcase (Temparray (tempi)) <1 Then
Tempstr=tempstr & "$Array $" & Temparray (Tempi)
End If
Next
Tempstr=right (Tempstr,len (TEMPSTR)-7)
Temparray=split (TempStr, "$Array $")
' Remove repeat picture end

' Convert relative picture address start
Tempstr= ""
For tempi=0 to Ubound (Temparray)
Tempstr=tempstr & "$Array $" & Definiteurl (Temparray (tempi), Tisturl)
Next
Tempstr=right (Tempstr,len (TEMPSTR)-7)
Tempstr=replace (TEMPSTR,CHR (0), "")
Temparray2=split (TempStr, "$Array $")
Tempstr= ""
' Convert relative to picture address end
' Picture replacement/Save
Set Re = New Regexp
Re.ignorecase = True
Re.global = True
For tempi=0 to Ubound (TempArray2)
Remotefileurl=temparray2 (TEMPI)
If remotefileurl<> "$False $" and savetf=true Then ' save picture
Arrsavefilename = Split (Remotefileurl, ".")
Strfiletype=lcase (Arrsavefilename (Ubound (arrsavefilename))) ' File type
If strfiletype= "ASP" or strfiletype= "ASA" or strfiletype= "aspx" or strfiletype= "CER" or strfiletype= "CDX" or strfiletype= "EXE" or strfiletype= "rar" or strfiletype= "zip" then
Uploadfiles= ""
Replacesaveremotefile=constr
Exit Function
End If

Randomize
Rannum=int (900*RND) +100
strFileName = year (Dtnow) & Right ("0" & Month (Dtnow), 2) & Right ("0" & Day (Dtnow), 2) & Right ("0" & Hour (Dtnow), 2 & Right ("0" & Minute (Dtnow), 2) & Right ("0" & Second (Dtnow), 2) & Rannum & "." & Strfiletype
Re.pattern =temparray (tempi)

If saveremotefile (Savepath & strfilename,remotefileurl) =true Then
'********************************
Pathtemp=savepath & strFileName
Constr=re.replace (constr,pathtemp)
Re.pattern=strinstalldir & Strchanneldir
Uploadfiles=uploadfiles & "|" & Re.replace (Savepath &strfilename, "")
Response.Flush ()
Response.Write "Picture Save Address:" & pathtemp & "<br>"
If Thumb_watermark=1 then call Skthumb.addwatermark (pathtemp) ' watermark
Else
Pathtemp=remotefileurl
Constr=re.replace (constr,pathtemp)
' Uploadfiles=uploadfiles & | ' & Remotefileurl
End If
ElseIf remotefileurl<> "$False $" and savetf=false Then ' do not save pictures
Re.pattern =temparray (tempi)
Constr=re.replace (Constr,remotefileurl)
Uploadfiles=uploadfiles & "|" & Remotefileurl
End If
Next
Set re=nothing
If uploadfiles<> "" Then
Uploadfiles=right (Uploadfiles,len (uploadfiles)-1)
End If
Replacesaveremotefile=constr
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.