加入收藏 | 设为首页 | 会员中心 | 我要投稿 | RSS
当前位置: 首页  文集文档  实用存档

将远程图片上传到自己空间ASP源码

时间:2006-12-07 00:00:00  来源:TIANZI.ORG  作者:天子  阅读:1449次
将远程图片直接传到空间的ASP代码

<html>
<head>
<meta http-equiv="content-Type" content="text/html; charset=gb2312">
<title>远程图片上传</title>
<style type=text/css>
a            { text-decoration: none; color: blue }
a:hover            { text-decoration: underline }
body            { scrollbar-base-color: #F8F8F8; scrollbar-arrow-color: #698CC3; font-size: 12pt; background-color: #ffffff }
</style>
<body topmargin="0" bgcolor="#F9F9F9">
<%
Server.ScriptTimeOut=99999
savepath="tianzi-org"
imgpath=request("imgpath")
if imgpath="" then
response.write "<form name=mofeiform method=post action=''><input type=text name=imgpath size=35> <input type=submit name=Submit001 value=远程上传>输入远程图片地址</form>"
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|jpeg)" '
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="tz-"&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 "<font color=red>没找到内容!</font>[<a href=# onclick=history.go(-1)>返回</a>]"
response.end
end if
objAdostream.SaveToFile(server.mappath(savepath&""&filename))
objAdostream.SetEOS
set objAdostream=nothing
imgpath01=savepath&""&filename
imgpath01=replace(imgpath01,"","/")
response.write ("图片地址:"&imgpath01&"[<a href=# onclick=history.go(-1)>继续上传</a>]") 
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
%>
</body>
</html>
来顶一下
返回首页
返回首页

发表评论 【查看全部条评论】
用户名:
密码:
验证码:
匿名:
推荐资讯
找了个帝国CMS程序和百度云服务器BCC
找了个帝国CMS程序和
帝国CMS管理员登陆页面修改美化
帝国CMS管理员登陆页
留言本从access数据库直接转入帝国MYSQL
留言本从access数据
MacBookPro安装win10双系统
MacBookPro安装win1
相关文章
    无相关信息
栏目更新
栏目热门