ASP远程保存图片
程序员文章站
2022-05-28 19:25:03
<% '先下载远程图片 url=\"http://www.im286.com/image... '远程图片地址 save...
<%
'先下载远程图片
url=\"http://www.im286.com/image... '远程图片地址
savepath=\"d:\photo\\" '保存路径
'为文件重命名
randomize
rannum=int(999*rnd)
filename=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&rannum
'为文件重命名结束
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)
objadostream.savetofile(savepath&filename&\".jpg\")
objadostream.seteos
set objadostream=nothing
'文件下载结束
set upload = server.createobject(\"persits.upload\") '打开对象
set file = upload.openfile(savepath&filename&\".jpg\") '打开已经保存的文件
if file.imagetype <> \"jpg\" and file.imagetype <> \"gif\" and file.imagetype <> \"bmp\" and file.imagetype <> \"png\" then
upload.deletefile savepath&filename&\".jpg\" '如果格式不正确就删除这张已下载的图片
response.write \"错误的图片格式\"
end if
'注销实例
set upload = nothing
set file = nothing
%>
'先下载远程图片
url=\"http://www.im286.com/image... '远程图片地址
savepath=\"d:\photo\\" '保存路径
'为文件重命名
randomize
rannum=int(999*rnd)
filename=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&rannum
'为文件重命名结束
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)
objadostream.savetofile(savepath&filename&\".jpg\")
objadostream.seteos
set objadostream=nothing
'文件下载结束
set upload = server.createobject(\"persits.upload\") '打开对象
set file = upload.openfile(savepath&filename&\".jpg\") '打开已经保存的文件
if file.imagetype <> \"jpg\" and file.imagetype <> \"gif\" and file.imagetype <> \"bmp\" and file.imagetype <> \"png\" then
upload.deletefile savepath&filename&\".jpg\" '如果格式不正确就删除这张已下载的图片
response.write \"错误的图片格式\"
end if
'注销实例
set upload = nothing
set file = nothing
%>