保存遠程圖片到本地文件夾!

 <%
Server.ScriptTimeOut=99999
const savepath="images" '圖片保存路徑
url="http://www.178yy.com/images/upfile/2007-4/2007423163032.jpg"
call saveimg(url) '函數調用

Function saveimg(url)
temp=split(url,".")
'以下是用時間與隨機數重命名文件名
randomize
ranNum=int(90000*rnd)+10000'隨機數
filename=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&temp(ubound(temp))'時間與隨機數組合命名圖片名稱
set xmlhttp=server.createobject("Microsoft.XMLHTTP")
xmlhttp.open "get",url,false
xmlhttp.send
img=xmlhttp.ResponseBody
set xmlhttp=nothing
set objAdostream=server.createobject("ADODB.Stream")
objAdostream.Open()
objAdostream.type=1
objAdostream.Write(img)
objAdostream.SaveToFile(server.mappath(savepath&"/"&filename))
objAdostream.SetEOS
set objAdostream=nothing
saveimg=filename'返回重新生成的圖片文件名稱
End Function
%>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章