<html> <head> <meta http-equiv="content-Type" content="text/html; charset=gb2312"> <title>远程图片上传</title> <style type=text/css> a { text-decoration: none; color: blue } a:hover { text-decoration: underline } body { scrollbar-base-color: #F8F8F8; scrollbar-arrow-color: #698CC3; font-size: 12pt; background-color: #ffffff } </style> <body topmargin="0" bgcolor="#F9F9F9"> <% Server.ScriptTimeOut=99999 savepath="tianzi-org" imgpath=request("imgpath") if imgpath="" then response.write "<form name=mofeiform method=post action=''><input type=text name=imgpath size=35> <input type=submit name=Submit001 value=远程上传>输入远程图片地址</form>" else filepath02=mofeifoldfso(savepath) savepath=savepath&""&year(now())&"-"&month(now()) filepath02=mofeifoldfso(savepath) urname01=myreplace(imgpath) end if
function myreplace(str) newstr=str set objregEx = new RegExp objregEx.IgnoreCase = true objregEx.Global = true objregEx.Pattern = "http://(.+?).(jpg|gif|png|bmp|jpeg)" ' set matches = objregEx.execute(str) for each match in matches newstr=replace(newstr,match.value,saveimg(match.value)) next myreplace=newstr end function
function saveimg(url) temp=split(url,".") filename="tz-"&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&"."&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) if objAdostream.size<200 then response.write "<font color=red>没找到内容!</font>[<a href=# onclick=history.go(-1)>返回</a>]" response.end end if objAdostream.SaveToFile(server.mappath(savepath&""&filename)) objAdostream.SetEOS set objAdostream=nothing imgpath01=savepath&""&filename imgpath01=replace(imgpath01,"","/") response.write ("图片地址:"&imgpath01&"[<a href=# onclick=history.go(-1)>继续上传</a>]") end function
Function mofeifoldfso(mpath) Set fso = Server.CreateObject("Scripting.FileSystemObject") if not fso.FolderExists(server.Mappath(mpath)) then fso.Createfolder(server.mappath(mpath)) set fso=nothing End Function %> </body> </html>