远程图片自动按文件夹上传到服务器-默飞出品 <% '远程图片自动按文件夹上传到服务器 '制作:默飞 server.scripttimeout=99999 savepath="upfiles" '图片保存路径,可以根据自己的需要,进行修改,如没有创建此文件夹,系统将自动创建 'qq:33224360 'home:http://mofei.xinxiu.com 'email:mofei5@yahoo.com.cn '2005-10-15 '版权说明不影响资源,请保留版权信息 imgpath=request("imgpath") if imgpath="" then response.write " 在输入框中输入远程图片地址,如图片不存在,程序自动放弃本次操作. 制作:默飞 qq:33224360 演示:http://mofei.xinxiu.com http://www.dns.com.cn域名65元,空间联系默飞可以享受八折优惠,信赖默飞冲天...." else filepath02=mofeifoldfso(savepath) savepath=savepath&"\"&year(now())&month(now()) filepath02=mofeifoldfso(savepath) urname01=myreplace(imgpath) end if function myreplace(str) newstr=str set objregex = new regexp objregex.ignorecase = true objregex.global = true objregex.pattern = "http://(.+?)\.(jpg|gif|png|bmp)" '定义文件后缀,可以增加你需要的后缀,按规律增加. set matches = objregex.execute(str) for each match in matches newstr=replace(newstr,match.value,saveimg(match.value)) next myreplace=newstr end function function saveimg(url) temp=split(url,".") filename=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&"."&temp(ubound(temp)) '文件名重命名结束 set xmlhttp=server.createobject("microsoft.xmlhttp") xmlhttp.open "get",url,false xmlhttp.send img=xmlhttp.responsebody set xmlhttp=nothing set objadostream=server.createobject("adodb.stream") objadostream.open() objadostream.type=1 objadostream.write(img) if objadostream.size<200 then response.write "没找到内容![返回]" response.end end if objadostream.savetofile(server.mappath(savepath&"\"&filename)) objadostream.seteos set objadostream=nothing imgpath01=savepath&"\"&filename '返回图片路径 imgpath01=replace(imgpath01,"\","/") response.write ("图片上传成功! [继续上传]") response.write (" http://www.dns.com.cn域名65元,空间联系默飞可以享受八折优惠,信赖默飞冲天....") 'ad response.write (" ") '根据你的系统需要,更改返回方式. end function function mofeifoldfso(mpath) set fso = server.createobject("scripting.filesystemobject") if not fso.folderexists(server.mappath(mpath)) then fso.createfolder(server.mappath(mpath)) set fso=nothing end function %> [ctrl+a 全选 注:如需引入外部js需刷新才能执行]
function myreplace(str) newstr=str set objregex = new regexp objregex.ignorecase = true objregex.global = true objregex.pattern = "http://(.+?)\.(jpg|gif|png|bmp)" '定义文件后缀,可以增加你需要的后缀,按规律增加. set matches = objregex.execute(str) for each match in matches newstr=replace(newstr,match.value,saveimg(match.value)) next myreplace=newstr end function
function saveimg(url) temp=split(url,".") filename=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&"."&temp(ubound(temp)) '文件名重命名结束 set xmlhttp=server.createobject("microsoft.xmlhttp") xmlhttp.open "get",url,false xmlhttp.send img=xmlhttp.responsebody set xmlhttp=nothing set objadostream=server.createobject("adodb.stream") objadostream.open() objadostream.type=1 objadostream.write(img) if objadostream.size<200 then response.write "没找到内容![返回]" response.end end if objadostream.savetofile(server.mappath(savepath&"\"&filename)) objadostream.seteos set objadostream=nothing imgpath01=savepath&"\"&filename '返回图片路径 imgpath01=replace(imgpath01,"\","/") response.write ("图片上传成功! [继续上传]") response.write (" http://www.dns.com.cn域名65元,空间联系默飞可以享受八折优惠,信赖默飞冲天....") 'ad response.write (" ") '根据你的系统需要,更改返回方式. end function
function mofeifoldfso(mpath) set fso = server.createobject("scripting.filesystemobject") if not fso.folderexists(server.mappath(mpath)) then fso.createfolder(server.mappath(mpath)) set fso=nothing end function %>
如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!
ASP中常用的22个FSO文件操作函数整理
asp中Request.ServerVariables的参数集合
ASP是使用正则提取内容里所有图片路径SRC的实现代码
javascript css实现三级目录(简单的)
Asp.Net MVC记住用户登录信息下次直接登录功能
一次性下载远程页面上的所有内容第1/2页
asp 多字段模糊搜索的函数
一个ACCESS数据库访问的类第1/3页
pjblog2的参数第1/2页
本人常用的asp代码 原创
网友评论