脚本宝典收集整理的这篇文章主要介绍了保存远程图片函数修改正版,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
趁今天有空,修正了一下这个函数,经测试,在本地
服务器通过,在空间商服务器也可
正常使用,没发现错误。我的卡巴斯基不报毒了。^_^
只要修改一下,这个函数是放在哪个网站都适用的。在此只与
添加图片为例说明一下调用方法,其它位置方法类似。
在我本机测试成功,由于现在
连不上空间的FTP,所以无办在空间上测试,发现问题请到群中提出。
一、把下面函数放到Ft_admin_conn.asp的最后
'
==================================
'=函&nbs
p;数 名:save
imgfile
'=功 能: 保存远程图片
'=参数说明:imgfileurl--远程图片地址
'=修改日期: 2006-4-19 13:20
'=程序作者:冷风
'=网 站:http://www.4fnet
.COM.cn
'==================================
function sav
eimgfile(imgfileurl)
dim img_ty
PE,savepath,imgfiletype,flag,imgbody
savepath="
../FUploa
DFile/"&
amp;year(now())&"-"&
;month(now())
flag=false
imgfiletype=right(imgfileurl,4)'获取远程图片的格式
img_type=".gif|.bmp|.
jpg|.png"'设置允许保存在本地的图片格式
typeArr=spl
IT(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.x
MLhttp")
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.file
Systemobject")
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=check
SQL("缩略图片地址",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
脚本宝典总结
以上是脚本宝典为你收集整理的保存远程图片函数修改正版全部内容,希望文章能够帮你解决保存远程图片函数修改正版所遇到的问题。
如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。