当前位置: 首页 > 图文教程 > 网络编程 > ASP > 保存远程图片函数修改正版

ASP
ASP下经常用的字符串等函数参考资料
asp下连接数据库 ASP链接数据库字符串大全总结
asp内置对象 ObjectContext 事务管理 详解
asp 内置对象 Application 详解
ASP中 SQL语句 使用方法
ASP 中 Split 函数的实例分析
ASP 中 DateDiff 函数详解 主要实现两日期加减操作
asp 存贮过程 (SQL版asp调用存储过程)
利用ASP实现在线生成电话图片效果脚本附演示
使用ASP记录在线用户的数量的代码
关于ASP生成伪参数技巧 简洁实用的伪(僞)参数
asp 关键词字符串分割如何实现方法
用ASP编写的加密和解密类
ASP之处理用Javascript动态添加的表单元素数据的代码
asp下最常用的19个基本技巧
一些Asp技巧和实用解决方法
asp实现一个统计当前在线用户的解决方案
asp下的一个很简单的验证码程序
asp又一个分页的代码例子
asp实现防止从外部提交数据的三种方法

ASP 中的 保存远程图片函数修改正版


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 79 ::
收藏到网摘: n/a

趁今天有空,修正了一下这个函数,经测试,在本地服务器通过,在空间商服务器也可正常使用,没发现错误。我的卡巴斯基不报毒了。^_^
只要修改一下,这个函数是放在哪个网站都适用的。在此只与添加图片为例说明一下调用方法,其它位置方法类似。
在我本机测试成功,由于现在连不上空间的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="/upload/tech/20091012/20091012011659_45645a27c4f1adc8a7a835976064a86d.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