程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> ASP編程 >> 關於ASP編程 >> 保存遠程圖片函數修改正版

保存遠程圖片函數修改正版

編輯:關於ASP編程
趁今天有空,修正了一下這個函數,經測試,在本地服務器通過,在空間商服務器也可正常使用,沒發現錯誤。我的卡巴斯基不報毒了。^_^

只要修改一下,這個函數是放在哪個網站都適用的。在此只與添加圖片為例說明一下調用方法,其它位置方法類似。

在我本機測試成功,由於現在連不上空間的FTP,所以無辦在空間上測試,發現問題請到群中提出。

一、把下面函數放到Ft_admin_conn.asp的最後

'==================================
'=函 數 名:saveimgfile
'=功 能: 保存遠程圖片
'=參數說明:imgfileurl--遠程圖片地址
'=修改日期: 2006-4-19 13:20
'=程序作者:冷風
'=網 站: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)'獲取遠程圖片的格式
img_type=".gif|.bmp|.jpg|.png"'設置允許保存在本地的圖片格式
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'如果不是允許保存到本地的圖片格式,則只連接遠程圖片
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 '如果保存成功,即返回遠程地址,只作遠程連接,避免一些防盜連網站不能保存
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">同時保存遠程圖片

2、在編輯圖片過程(editpic)中的相同地方添加相應的代碼即可。

ok,完工

希望大家能舉一返回,其它用到圖片的地方也是一樣的調用方法。

歡迎光臨本站:http://www.4fnet.com.cn
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved