ReSaveRemoteFile函數(shù)之a(chǎn)sp實(shí)現(xiàn)查找文件保存替換的代碼
更新時(shí)間:2007年09月01日 22:08:19 作者:
'================================================
'函數(shù)名:ReSaveRemoteFile
'作 用:查找文件保存替換
'參 數(shù):Str ----原字符串
'參 數(shù):url ----當(dāng)然網(wǎng)站URL
'參 數(shù):Dir -----保存目錄
'參 數(shù):InSave ------是否保存,True,False
'返回值:格式化取后的字符串
'================================================
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(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)'得到文件地址
Response.Write(strTempUrl)
IF InSave=True then
Arr_Path=Split(Dir,"/")
'----------建目錄-----------------------
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,"/")
'----------檢查文件是否存在.如果存在換文件名------------------
Do while True
FileTemp=Dir & MakeRandom(5) & TempUrlArray(Ubound(TempUrlArray))'生成隨機(jī)文件名
If CheckFile(FileTemp)=False then
Exit Do
end if
loop
'-------------------------------------------------------------------
Response.Write(FileTemp)
If SaveRemoteFile(FileTemp,strTempUrl)=True then
Response.Write("保存成功")&"<Br>"
s_Content = Replace(s_Content,sContentUrl(i),FileTemp, 1, -1, 1)'替換地址
Else
Response.Write("保存失敗")&"<Br>"
End if
Else
s_Content = Replace(s_Content,sContentUrl(i),strTempUrl, 1, -1, 1)'替換地址
End If
Next
Set re = Nothing
PictureExist = True
ReSaveRemoteFile = s_Content
Exit Function
End Function
'函數(shù)名:ReSaveRemoteFile
'作 用:查找文件保存替換
'參 數(shù):Str ----原字符串
'參 數(shù):url ----當(dāng)然網(wǎng)站URL
'參 數(shù):Dir -----保存目錄
'參 數(shù):InSave ------是否保存,True,False
'返回值:格式化取后的字符串
'================================================
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(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)'得到文件地址
Response.Write(strTempUrl)
IF InSave=True then
Arr_Path=Split(Dir,"/")
'----------建目錄-----------------------
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,"/")
'----------檢查文件是否存在.如果存在換文件名------------------
Do while True
FileTemp=Dir & MakeRandom(5) & TempUrlArray(Ubound(TempUrlArray))'生成隨機(jī)文件名
If CheckFile(FileTemp)=False then
Exit Do
end if
loop
'-------------------------------------------------------------------
Response.Write(FileTemp)
If SaveRemoteFile(FileTemp,strTempUrl)=True then
Response.Write("保存成功")&"<Br>"
s_Content = Replace(s_Content,sContentUrl(i),FileTemp, 1, -1, 1)'替換地址
Else
Response.Write("保存失敗")&"<Br>"
End if
Else
s_Content = Replace(s_Content,sContentUrl(i),strTempUrl, 1, -1, 1)'替換地址
End If
Next
Set re = Nothing
PictureExist = True
ReSaveRemoteFile = s_Content
Exit Function
End Function
相關(guān)文章
asp短信接口源碼 比較簡(jiǎn)單但也挺實(shí)用用的(兩個(gè)寫(xiě)法)
這是關(guān)于短信接口的一些調(diào)用方法,asp的,兩個(gè)方式,調(diào)用短信接口都比較簡(jiǎn)單,但也比較實(shí)用2012-01-01asp下將數(shù)據(jù)庫(kù)中的信息存儲(chǔ)至XML文件中
asp下將數(shù)據(jù)庫(kù)中的信息存儲(chǔ)至XML文件中...2007-04-04asp實(shí)現(xiàn)后臺(tái)添加wma視頻文件前臺(tái)顯示
想用asp來(lái)實(shí)現(xiàn)后臺(tái)添加wma視頻文件,前臺(tái)顯示所添加的這個(gè)視頻文件,本文提供實(shí)現(xiàn)代碼2012-12-12檢查access數(shù)據(jù)庫(kù)中是否存在某個(gè)名字的表的asp代碼
首先調(diào)用adodb.connection對(duì)象中的openSchema函數(shù),這樣會(huì)得到一個(gè)Recordset,其中每一條“紀(jì)錄”對(duì)應(yīng)著數(shù)據(jù)庫(kù)中的一張表,“紀(jì)錄”的每個(gè)“字段”包含了對(duì)應(yīng)表的某方面信息。其中TABLE_NAME字段包含了對(duì)應(yīng)表的名稱2009-06-06好久沒(méi)發(fā)布新玩意,完成了tsys的少年不在版
好久沒(méi)發(fā)布新玩意,完成了tsys的少年不在版...2007-01-01