<%
if Request.QueryString("action")="add" then
content=lcase(Request.Form("content"))
regstr=".?[\.\/\\\w-:]+\.(gif|jpg)"
url=Replace(Replace(RegExp_Execute(regstr,content),"'",""),"""","")
array_url=split(url,"|||")
for i=0 to ubound(array_url)
Response.Write(array_url(i)&"<br/>")
fname=RegExp_Execute("\w+\.(jpg|gif)",array_url(i))
Response.Write(Replace(fname,"|||",""))
filepath=Replace(fname,"|||","")
call saveimage(array_url(i),filepath)
next
end if
'返回匹配值
Function RegExp_Execute(patrn, strng)
Dim regEx, Match, Matches,values '建立变量。
Set regEx = New RegExp '建立正则表达式。
regEx.Pattern = patrn '设置模式。
regEx.IgnoreCase = true '设置是否区分字符大小写。
regEx.Global = True '设置全局可用性。
Set Matches = regEx.Execute(strng) '执行搜索。
For Each Match in Matches '遍历匹配集合。
values=values&Match.Value&"|||"
Next
RegExp_Execute = values
End Function
'保存图片
function saveimage(from,tofile)
On Error Resume Next
dim geturl,objStream,imgs
geturl=trim(from)
imgs=getHTTPPage(geturl)'取得图片的具休内容的过程
Set objStream = Server.CreateObject("ADODB.Stream")'建立ADODB.Stream对象,必须要ADO 2.5以上版本
With objStream
.Type =1'以二进制模式打开
.Open()
.write (imgs)'将字符串内容写入缓冲
.SaveToFile server.mappath(tofile),2'-将缓冲的内容写入文件
.Close()'关闭对象
End With
set objstream=nothing
end function
'取得图片内容
function getHTTPPage(url)
on error resume next
dim http
set http=server.createobject("Microsoft.XMLHTTP")'使用xmlhttp的方法来获得图片的内容
With http
.open "GET",url,false
.send()
End With
if Http.readystate<>4 then
exit function
end if
getHTTPPage=Http.responseBody
set http=nothing
if err.number<>0 then err.Clear
end function
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="?action=add">
<textarea name="content" cols="60" rows="6" id="content"></textarea>
<input type="submit" name="Submit" value="提交">
</form></td>
</tr>
</table>
</body>
</html>
发表于 @ 2006年08月23日 17:09:00 | 评论( loading... ) | 举报| 收藏