保存远程图片函数修改正版
2018-09-06 12:22
  趁今天有空,修正了一下这个函数,经测试,在本地服务器通过,在空间商服务器也可正常使用,没发现错误。我的卡巴斯基不报毒了。^_^ 
只要修改一下,这个函数是放在哪个网站都适用的。在此只与添加图片为例说明一下调用方法,其它位置方法类似。 
在我本机测试成功,由于现在连不上空间的FTP,所以无办在空间上测试,发现问题请到群中提出。 
一、把下面函数放到Ft_admin_conn.asp的最后 
================================== 
=函数名:saveimgfile 
=功能:保存远程图片 
=参数说明:imgfileurl--远程图片地址 
=修改日期:2006-4-1913:20 
=程序作者:冷风 
=网站:
================================== 
functionsaveimgfile(imgfileurl) 
dimimg_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,) 
fori=0toubound(typeArr)-1 
ifimgfiletype=typeArr(i)then 
flag=true 
exitfor 
endif 
next 
ifflag=falsethen如果不是允许保存到本地的图片格式,则只连接远程图片 
saveimgfile=imgfileurl 
else 
setxml_http=server.createobject(microsoft.xmlhttp) 
xml_http.openget,imgfileurl,false 
xml_http.send 
imgbody=xml_http.responsebody 
setxml_http=nothing 
serverpath=server.mappath(savepath) 
setfilefolder=server.createobject(scripting.filesystemobject) 
iffilefolder.folderexists(serverpath)=falsethen 
filefolder.createfolder(serverpath) 
endif 
randomize 
savepath=savepath&/&year(now())&month(now())&day(now())&hour(now())&minute(now())&int(10*rnd)&imgfiletype 
setadodbs=server.createobject(adodb.stream) 
adodbs.open 
adodbs.type=1 
adodbs.writeimgbody 
adodbs.savetofile(server.mappath(savepath))保存到本地 
adodbs.seteos 
setadodbs=nothing 
iffilefolder.fileexists(server.mappath(savepath))=falsethen如果保存成功,即返回远程地址,只作远程连接,避免一些防盗连网站不能保存 
saveimgfile=imgfileurl 
else 
savepath=replace(savepath,../,) 
saveimgfile=savepath 
endif 
setfilefolder=nothing 
endif 
endfunction 
二、打开admin/admin_pic.asp文件 
1、找到:添加图片过程中的pic_pic=checksql(缩略图片地址,request.form(pic),1,100)(大概在第368行)在下面插入代码: 
ifleft(pic_url,7)=
pic_url=saveimgfile(pic_url) 
pic_pic=pic_url 
endif 
再找到:<inputtype=submitname=Submitvalue=确定新增>(大概在第481行)插入以下代码: 
<inputtype=checkboxname=savevalue=true>同时保存远程图片 
2、在编辑图片过程(editpic)中的相同地方添加相应的代码即可。 
ok,完工 
希望大家能举一返回,其它用到图片的地方也是一样的调用方法。 
欢迎光临本站
上一篇:asp网页邮箱访问