让我们一起爱米兰
站内搜搜:
移动设备
请扫描二维码
或访问
m.milan100.com
您所在的位置 -> 米兰百分百 -> ASP -> asp+xmlhttp 保存网络图片

asp+xmlhttp 保存网络图片

点击数:913 发表时间:2010-07-23 17:31:55 作者: 来源链接:
分享到:
分享到微信

Class xhttp
private cset,sUrl
Private Sub Class_Initialize()
cset="UTF-8"
end sub


Private Sub Class_Terminate()
End Sub

Public Property LET URL(theurl)
sUrl=theurl
end property

public property GET BasePath()
BasePath=mid(sUrl,1,InStrRev(sUrl,"/")-1)
end property

public property GET FileName()
FileName=mid(sUrl,InStrRev(sUrl,"/")+1)
end property
public property GET Html()
Html=BytesToBstr(getBody(sUrl))
end property
private Function BytesToBstr(body)
'Cset:GB2312 UTF-8
dim objstream
set objstream = Server.CreateObject("adodb.stream")
with objstream
.Type = 1 '设置返回数据类型为二进制
.Mode = 3 '打开模式为读写
.Open
.Write body '将指定的数据装入对像中 body为内容
.Position = 0 '指定对像内数据的当前指针
.Type = 2 '设置返回数据类型为文本
.Charset = Cset '设定字符集类型
BytesToBstr = .ReadText '取对象内的文本
.Close
end with
set objstream = nothing
End Function

private function getBody(surl)
dim xmlHttp
set xmlHttp=server.createobject("MSXML2.XMLHTTP")
xmlHttp.open "GET",surl,false
xmlHttp.send
if xmlHttp.readystate<>4 then
exit function
end if
getBody=xmlhttp.responsebody
set xmlHttp=nothing
end function


Public function saveimage(tofile)
dim objStream,imgs
imgs=getBody(sUrl)'取得图片的具休内容的过程
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

end class


TEST:
dim o
set o=new xhttp
o.url="http://www.baidu.com/img/logo-yy.gif"
o.saveimage "blue.gif"
set o=nothing

0
很 好
0
一 般
0
差 劲
热门新闻
相关文章
上一篇: 利用asp获得图片尺寸大小
下一篇: ASP+MsSqlServer 存储过程分页
评论区
匿名

返回首页 | 收藏本页 | 回到顶部
Copyright 2010. 米兰百分百 Powered By Bridge.
京ICP备15050557号