保存遠(yuǎn)程圖片函數(shù)修改正版
更新時(shí)間:2006年07月15日 00:00:00 作者:
趁今天有空,修正了一下這個(gè)函數(shù),經(jīng)測(cè)試,在本地服務(wù)器通過,在空間商服務(wù)器也可正常使用,沒發(fā)現(xiàn)錯(cuò)誤。我的卡巴斯基不報(bào)毒了。^_^
只要修改一下,這個(gè)函數(shù)是放在哪個(gè)網(wǎng)站都適用的。在此只與添加圖片為例說明一下調(diào)用方法,其它位置方法類似。
在我本機(jī)測(cè)試成功,由于現(xiàn)在連不上空間的FTP,所以無辦在空間上測(cè)試,發(fā)現(xiàn)問題請(qǐng)到群中提出。
一、把下面函數(shù)放到Ft_admin_conn.asp的最后
'==================================
'=函 數(shù) 名:saveimgfile
'=功 能: 保存遠(yuǎn)程圖片
'=參數(shù)說明:imgfileurl--遠(yuǎn)程圖片地址
'=修改日期: 2006-4-19 13:20
'=程序作者:冷風(fēng)
'=網(wǎng) 站:http://www.4fnet.com.cn
'==================================
function saveimgfile(imgfileurl)
dim img_type,savepath,imgfiletype,flag,imgbody
savepath="../FUploadFile/"&year(now())&"-"&month(now())
flag=false
imgfiletype=right(imgfileurl,4)'獲取遠(yuǎn)程圖片的格式
img_type=".gif|.bmp|.jpg|.png"'設(shè)置允許保存在本地的圖片格式
typeArr=split(img_type,"|")
for i=0 to ubound(typeArr)-1
if imgfiletype=typeArr(i) then
flag=true
exit for
end if
next
if flag=false then'如果不是允許保存到本地的圖片格式,則只連接遠(yuǎn)程圖片
saveimgfile=imgfileurl
else
set xml_http=server.createobject("microsoft.xmlhttp")
xml_http.open "get",imgfileurl,false
xml_http.send
imgbody=xml_http.responsebody
set xml_http=nothing
serverpath=server.mappath(savepath)
set filefolder=server.createobject("scripting.filesystemobject")
if filefolder.folderexists(serverpath)=false then
filefolder.createfolder(serverpath)
end if
randomize
savepath=savepath&"/"&year(now())&month(now())&day(now())&hour(now())&minute(now())&int(10*rnd)&imgfiletype
set adodbs=server.createobject("adodb.stream")
adodbs.open
adodbs.type=1
adodbs.write imgbody
adodbs.savetofile(server.mappath(savepath))'保存到本地
adodbs.seteos
set adodbs=nothing
if filefolder.fileexists(server.mappath(savepath))=false then '如果保存成功,即返回遠(yuǎn)程地址,只作遠(yuǎn)程連接,避免一些防盜連網(wǎng)站不能保存
saveimgfile=imgfileurl
else
savepath=replace(savepath,"../","")
saveimgfile=savepath
end if
set filefolder=nothing
end if
end function
二、打開admin/admin_pic.asp文件
1、找到:添加圖片過程中的 pic_pic=checksql("縮略圖片地址",request.form("pic"),1,100) (大概在第368行)在下面插入代碼:
if left(pic_url,7)="http://" and request.form("save")="true" then
pic_url=saveimgfile(pic_url)
pic_pic=pic_url
end if
再找到:<input type="submit" name="Submit" value="確定新增"> (大概在第481行)插入以下代碼:
<input type="checkbox" name="save" value="true">同時(shí)保存遠(yuǎn)程圖片
2、在編輯圖片過程(editpic)中的相同地方添加相應(yīng)的代碼即可。
ok,完工
希望大家能舉一返回,其它用到圖片的地方也是一樣的調(diào)用方法。
歡迎光臨本站:http://www.4fnet.com.cn
只要修改一下,這個(gè)函數(shù)是放在哪個(gè)網(wǎng)站都適用的。在此只與添加圖片為例說明一下調(diào)用方法,其它位置方法類似。
在我本機(jī)測(cè)試成功,由于現(xiàn)在連不上空間的FTP,所以無辦在空間上測(cè)試,發(fā)現(xiàn)問題請(qǐng)到群中提出。
一、把下面函數(shù)放到Ft_admin_conn.asp的最后
'==================================
'=函 數(shù) 名:saveimgfile
'=功 能: 保存遠(yuǎn)程圖片
'=參數(shù)說明:imgfileurl--遠(yuǎn)程圖片地址
'=修改日期: 2006-4-19 13:20
'=程序作者:冷風(fēng)
'=網(wǎng) 站:http://www.4fnet.com.cn
'==================================
function saveimgfile(imgfileurl)
dim img_type,savepath,imgfiletype,flag,imgbody
savepath="../FUploadFile/"&year(now())&"-"&month(now())
flag=false
imgfiletype=right(imgfileurl,4)'獲取遠(yuǎn)程圖片的格式
img_type=".gif|.bmp|.jpg|.png"'設(shè)置允許保存在本地的圖片格式
typeArr=split(img_type,"|")
for i=0 to ubound(typeArr)-1
if imgfiletype=typeArr(i) then
flag=true
exit for
end if
next
if flag=false then'如果不是允許保存到本地的圖片格式,則只連接遠(yuǎn)程圖片
saveimgfile=imgfileurl
else
set xml_http=server.createobject("microsoft.xmlhttp")
xml_http.open "get",imgfileurl,false
xml_http.send
imgbody=xml_http.responsebody
set xml_http=nothing
serverpath=server.mappath(savepath)
set filefolder=server.createobject("scripting.filesystemobject")
if filefolder.folderexists(serverpath)=false then
filefolder.createfolder(serverpath)
end if
randomize
savepath=savepath&"/"&year(now())&month(now())&day(now())&hour(now())&minute(now())&int(10*rnd)&imgfiletype
set adodbs=server.createobject("adodb.stream")
adodbs.open
adodbs.type=1
adodbs.write imgbody
adodbs.savetofile(server.mappath(savepath))'保存到本地
adodbs.seteos
set adodbs=nothing
if filefolder.fileexists(server.mappath(savepath))=false then '如果保存成功,即返回遠(yuǎn)程地址,只作遠(yuǎn)程連接,避免一些防盜連網(wǎng)站不能保存
saveimgfile=imgfileurl
else
savepath=replace(savepath,"../","")
saveimgfile=savepath
end if
set filefolder=nothing
end if
end function
二、打開admin/admin_pic.asp文件
1、找到:添加圖片過程中的 pic_pic=checksql("縮略圖片地址",request.form("pic"),1,100) (大概在第368行)在下面插入代碼:
if left(pic_url,7)="http://" and request.form("save")="true" then
pic_url=saveimgfile(pic_url)
pic_pic=pic_url
end if
再找到:<input type="submit" name="Submit" value="確定新增"> (大概在第481行)插入以下代碼:
<input type="checkbox" name="save" value="true">同時(shí)保存遠(yuǎn)程圖片
2、在編輯圖片過程(editpic)中的相同地方添加相應(yīng)的代碼即可。
ok,完工
希望大家能舉一返回,其它用到圖片的地方也是一樣的調(diào)用方法。
歡迎光臨本站:http://www.4fnet.com.cn
相關(guān)文章
XMLHttp ASP遠(yuǎn)程獲取網(wǎng)頁內(nèi)容代碼
asp下利用xmlhttp獲取網(wǎng)頁內(nèi)容的方法這個(gè)方法一般比較通用的,然后通過字符截取網(wǎng)頁的內(nèi)容。2008-11-11asp獲取遠(yuǎn)程網(wǎng)頁的指定內(nèi)容的實(shí)現(xiàn)代碼
用ASP獲取遠(yuǎn)程網(wǎng)頁的指定內(nèi)容,可以輕易獲取到別人網(wǎng)頁的指定的某些內(nèi)容,其實(shí)也就是ASP小偷程序原理了,需要的朋友可以參考下。2010-10-10asp下利用XMLHTTP 從其他頁面獲取數(shù)據(jù)的代碼
asp下利用XMLHTTP 從其他頁面獲取數(shù)據(jù)的代碼...2007-11-11網(wǎng)站生成靜態(tài)頁面攻略2:數(shù)據(jù)采集
網(wǎng)站生成靜態(tài)頁面攻略2:數(shù)據(jù)采集...2006-08-08