'================================================
'函数名:ReSaveRemoteFile
'作用:查找文件保存替换
'参数:Str----原字符串
'参数:url----当然网站URL
'参数:Dir-----保存目录
'参数:InSave------是否保存,True,False
'返回值:格式化取后的字符串
'================================================
PublicFunctionReSaveRemoteFile(ByValstr,ByValURL,ByValDir,InSave)
Dims_Content
Dimre
DimContentFile,ContentFileUrl
DimstrTempUrl,strFileUrl,DirTemp,PathTemp,FileTemp,Tempi,TempUrlArray,Arr_Path
DimsAllowExtName
sAllowExtName="rm|swf"
s_Content=str
OnErrorResumeNext
Setre=NewRegExp
re.IgnoreCase=True
re.Global=True
re.Pattern="((src=|href=)((S)+[.]{1}("&sAllowExtName&")))"
SetContentFile=re.Execute(s_Content)
DimsContentUrl(),n,i,bRepeat
n=0
ForEachContentFileUrlInContentFile
strFileUrl=Replace(Replace(Replace(Replace(ContentFileUrl.Value,"src=","",1,-1,1),"href=","",1,-1,1),"'",""),Chr(34),"")
Ifn=0Then
n=n+1
ReDimsContentUrl(n)
sContentUrl(n)=strFileUrl
Else
bRepeat=False
Fori=1ToUBound(sContentUrl)
IfUCase(strFileUrl)=UCase(sContentUrl(i))Then
bRepeat=True
ExitFor
EndIf
Next
IfbRepeat=FalseThen
n=n+1
ReDimPreservesContentUrl(n)
sContentUrl(n)=strFileUrl
EndIf
EndIf
Next
Ifn=0Then
ReSaveRemoteFile=s_Content
ExitFunction
EndIf
Fori=1Ton
strTempUrl=sContentUrl(i):strTempUrl=FormatRemoteUrl(strTempUrl,URL)'得到文件地址
Response.Write(strTempUrl)
IFInSave=Truethen
Arr_Path=Split(Dir,"/")
'----------建目录-----------------------
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
'------------------------------------------------------
TempUrlArray=Split(strTempUrl,"/")
'----------检查文件是否存在.如果存在换文件名------------------
DowhileTrue
FileTemp=Dir&MakeRandom(5)&TempUrlArray(Ubound(TempUrlArray))'生成随机文件名
IfCheckFile(FileTemp)=Falsethen
ExitDo
endif
loop
'-------------------------------------------------------------------
Response.Write(FileTemp)
IfSaveRemoteFile(FileTemp,strTempUrl)=Truethen
Response.Write("保存成功")&"<Br>"
s_Content=Replace(s_Content,sContentUrl(i),FileTemp,1,-1,1)'替换地址
Else
Response.Write("保存失败")&"<Br>"
Endif
Else
s_Content=Replace(s_Content,sContentUrl(i),strTempUrl,1,-1,1)'替换地址
EndIf
Next
Setre=Nothing
PictureExist=True
ReSaveRemoteFile=s_Content
ExitFunction
EndFunction