28,391
社区成员
发帖
与我相关
我的任务
分享
<%
'==================================
'=功 能: 保存远程文件
'==================================
Sub saveimgfile(s_weburl)
On Error Resume Next
Dim savepath,s_name,s_ext,imgbody,xml_http,adodbs,files
savepath="/FUploadFile/" '保存的文件夹
files=Mid(s_weburl,InstrRev(s_weburl,"/")+1) '原文件名
s_ext=LCase(Right(s_weburl,4))'获取远程文件的格式
If InStr(".gif|.bmp|.jpeg|.jpg|.png|.html",s_ext)>0 Then
'为了安全最好定义几种格式
Set xml_http=Server.CreateObject("Microsoft.XMLHTTP")
xml_http.open "get",s_weburl,False
xml_http.send
imgbody=xml_http.responsebody
Set xml_http=Nothing
Randomize
files=savepath&files
'files=savepath&Day(date)&"-"&rnd*1000&s_ext '建议重新命名文件
Set adodbs = Server.CreateObject("Adodb.Stream")
With adodbs
.Open
.Type = 1
.Write imgbody
.SaveToFile server.MapPath(files)
.Cancel()
.Close()
End With
Set adodbs=Nothing
End If
'实用时还需要做文件重名等处理。
End Sub
Call saveimgfile("http://www.scscms.com/scs_img/logo.png")
%>
System.Net.WebClient myWebClient = new System.Net.WebClient();
//保存文件
myWebClient.DownloadFile("http://www.baidu.com/img/baidu_jgylogo3.gif", "D:\\save.gif");