<%
'遠(yuǎn)程圖片自動(dòng)按文件夾上傳到服務(wù)器
Server.ScriptTimeOut=99999
savepath="upfiles" '圖片保存路徑,可以根據(jù)自己的需要,進(jìn)行修改,如沒有創(chuàng)建此文件夾,系統(tǒng)將自動(dòng)創(chuàng)建
imgpath=request("imgpath")
if imgpath="" then
response.write "<form name=mofeiform method=post action='uppic.asp'><input type=text name=imgpath size=35> <input type=submit name=Submit001 value=上傳></form><br>在輸入框中輸入遠(yuǎn)程圖片地址,如圖片不存在,程序自動(dòng)放棄本次操作.<BR>"
else
filepath02=mofeifoldfso(savepath)
savepath=savepath&"\"&year(now())&month(now())&"\"&day(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)" '定義文件后綴,可以增加你需要的后綴,按規(guī)律增加.
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=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&"."&temp(ubound(temp))
'文件名重命名結(jié)束
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>沒找到內(nèi)容!</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 ("圖片上傳成功! [<a href=# onclick=history.go(-1)>繼續(xù)上傳</a>]")
response.write ("<br><img src="&imgpath01&" border=0 alt=默飛制作>") '根據(jù)你的系統(tǒng)需要,更改返回方式.
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
%>
該文章在 2011/2/16 0:32:54 編輯過