asp 下载文件到服务器

<%
Function GetWebData(byval strUrl)
dim curlpath
dim Retrieval
Set Retrieval = Server.CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", strUrl, False, "", ""
.Send
GetWebData =.ResponseBody
End With
Set Retrieval = Nothing
End Function

sub SaveImg(FileName,Data)
set ads=server.CreateObject("Adodb.Stream")
with ads
.Type=1
.Open
.Write Data
.SaveToFile server.MapPath(FileName),2
.Cancel()
.Close()
end with
set ads=nothing
end sub

sub showDownHtml
 Response.Write "<html><body>"
 Response.Write "<form action=" & Request.ServerVariables("SCRIPT_NAME") & " method=post>"
 Response.Write "GetUrl :<input name=u type=text size=30><br>"
 Response.Write "Code   :<input name=checkcode type=password>"
 Response.Write "<input name=submit type=submit>"
 Response.Write "</form>"
 Response.Write "</body></html>"
end sub

showDownHtml
checkcode = Trim(Request.Form("checkcode"))
If checkcode="456852" Then
 dim imgurl
 dim aryFileName
 imgurl = Trim(Request.Form("u"))
 if len(imgurl) = 0 then
  Response.redirect "/index.asp"
 Else
  if LCase(left(imgurl,7)) <> "http://" then
   imgurl = "http://" & imgurl
  end if
 end if
 aryFileName=split(imgUrl,"/")
 call SaveImg(aryFileName(ubound(aryFileName)),GetWebData(imgurl))
 Response.write "DownUrl:<a href=" & imgurl & ">" & imgurl & "</a>"
End if

%>

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据