This article mainly shares the function code for ASP replacement and saving remote pictures. Friends who need it can refer to it
ASP uses functions to replace and save remote pictures, complete the functions of automatically collecting and extracting pictures, automatically judge repeating pictures in the function, intelligently analyze the link path, and convert it into a relative picture address and save it in the website directory you specified. We can use this function in the background editor. When you copy the content containing the picture, this code will automatically upload the picture for you. At the same time, this code is also an important processing function in the collection program. The function code is as follows:
- FunctionReplaceSaveRemoteFile(ConStr,strInstallDir,strChannelDir,SaveTf,TistUrl)
- IfConStr=$False$orConStr=orstrInstallDir=orstrChannelDir=Then
- ReplaceSaveRemoteFile=ConStr
- ExitFunction
- EndIf
- DimTempStr, TempStr2, TempStr3, Re, Matches, Match, Temppi, TempArray, TempArray2
- SetRe=NewRegexp
- Re.IgnoreCase=True
- Re.Global=True
- Re.Pattern=]>
- SetMatches=Re.Execute(ConStr)
- ForEachMatchinMatches
- IfTempStr<>then
- TempStr=TempStr&$Array$&Match.Value
- Else
- TempStr=Match.Value
- Endif
- Next
- IfTempStr<>Then
- TempArray=Split(TempStr,$Array$)
- TempStr=
- ForTempi=0ToUbound(TempArray)
- Re.Pattern=src/s*=/s*.+?/.(gif|jpg|bmp|jpeg|psd|png|svg|dxf|wmf|tiff)
- SetMatches=Re.Execute(TempArray(Tempi))
- ForEachMatchinMatches
- IfTempStr<>then
- TempStr=TempStr&$Array$&Match.Value
- Else
- TempStr=Match.Value
- Endif
- Next
- Next
- Endif
- IfTempStr<>Then
- Re.Pattern=src/s*=/s*
- TempStr=Re.Replace(TempStr,)
- EndIf
- SetMatches=nothing
- SetRe=nothing
- IfTempStr=orIsNull(TempStr)=TrueThen
- ReplaceSaveRemoteFile=ConStr
- Exitfunction
- Endif
- TempStr=Replace(TempStr,,)
- TempStr=Replace(TempStr,',)
- TempStr=Replace(TempStr,,)
- DimRemoteFileurl,SavePath,PathTemp,DtNow,strFileName,strFileType,ArrSaveFileName,RanNum,Arr_Path
- DtNow=Now()
- IfSaveTf=Truethen
- SavePath=strChannelDir&/&year(DtNow)&right(0&month(DtNow),2)&/
- response.write link path: &savepath&
- Arr_Path=Split(SavePath,/)
- PathTemp=
- ForTempi=0ToUbound(Arr_Path)
- IfTempi=0Then
- PathTemp=Arr_Path(0)&/
- ElseIfTempi=Ubound(Arr_Path)Then
- ExitFor
- Else
- PathTemp=PathTemp&Arr_Path(Tempi)&/
- EndIf
- IfCheckDir(PathTemp)=FalseThen
- IfMakeNewsDir(PathTemp)=FalseThen
- SaveTf=False
- ExitFor
- EndIf
- EndIf
- Next
- EndIf
- 'Remove duplicate pictures
- TempArray=Split(TempStr,$Array$)
- TempStr=
- ForTempi=0ToUbound(TempArray)
- IfInstr(Lcase(TempStr),Lcase(TempArray(Temppi)))<1Then
- TempStr=TempStr&$Array$&TempArray(Temppi)
- EndIf
- Next
- TempStr=Right(TempStr,Len(TempStr)-7)
- TempArray=Split(TempStr,$Array$)
- 'Convert relative picture address
- TempStr=
- ForTempi=0ToUbound(TempArray)
- TempStr=TempStr&$Array$&DefiniteUrl(TempArray(Temppi),TistUrl)
- Next
- TempStr=Right(TempStr,Len(TempStr)-7)
- TempStr=Replace(TempStr,Chr(0),)
- TempArray2=Split(TempStr,$Array$)
- TempStr=
- 'Image replacement/save
- SetRe=NewRegexp
- Re.IgnoreCase=True
- Re.Global=True
- ForTempi=0ToUbound(TempArray2)
- RemoteFileUrl=TempArray2(Tempi)
- IfRemoteFileUrl<>$False$AndSaveTf=TrueThen'Save Image
- ArrSaveFileName=Split(RemoteFileurl,.)
- strFileType=Lcase(ArrSaveFileName(Ubound(ArrSaveFileName)))' file type
- IfstrFileType=aspostrFileType=asaorstrFileType=aspxorstrFileType=cerorstrFileType=cdxorstrFileType=exeorstrFileType=rarostrFileType=zipthen
- UploadFiles=
- ReplaceSaveRemoteFile=ConStr
- ExitFunction
- EndIf
- 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)&right(0&second(DtNow),2 )&ranNum&.&strFileType
- Re.Pattern=TempArray(Tempi)
- IfSaveRemoteFile(SavePath&strFileName,RemoteFileUrl)=TrueThen
- '************************************
- PathTemp=SavePath&strFileName
- ConStr=Re.Replace(ConStr,PathTemp)
- Re.Pattern=strInstallDir&strChannelDir&/
- UploadFiles=UploadFiles&|&Re.Replace(SavePath&strFileName,)
- Else
- PathTemp=RemoteFileUrl
- ConStr=Re.Replace(ConStr,PathTemp)
- 'UploadFiles=UploadFiles&|&RemoteFileUrl
- EndIf
- ElseIfRemoteFileurl<>$False$andSaveTf=FalseThen' does not save the image
- Re.Pattern=TempArray(Tempi)
- ConStr=Re.Replace(ConStr,RemoteFileUrl)
- UploadFiles=UploadFiles&|&RemoteFileUrl
- EndIf
- Next
- SetRe=nothing
- IfUploadFiles<>Then
- UploadFiles=Right(UploadFiles,Len(UploadFiles)-1)
- EndIf
- ReplaceSaveRemoteFile=ConStr
- Endfunction
Function parameter description:
ConStr: The string to replace
Parameters: SaveTf: Whether to save the file, False does not save, True save
Parameters: TistUrl: Current web page address
The above is the code for ASP replacement and saving remote picture function, I hope it will be helpful to everyone's learning.