<!--#include file="../../lib/base.asp"-->
<%
Dim url
url = Trim(request("url"))
downloadfile url

function save_outfile(byval t0)
	on error resume next
	dim stm,http,filedata,filesize,filename
	filename="temp.png"
	set http=server.createobject(xmlhttp)
	with http
		.open "get",t0,false,"",""
		.send
		filedata=.responsebody
		filesize=eycms.getnum(round(eycms.lenb(filedata))/1024)
	end with
	set stm=server.createobject("adodb.stream")
	with stm
		.type=1
		.open
		.write filedata
		.savetofile server.mappath(filename), 2
		.cancel
	.close
	end with
	set stm=nothing
	if err then
		save_outfile=false
	else
		save_outfile=true
	end if
end function

function downloadfile(fullpath)
	downloadfile = False
	If left(LCase(fullpath),7)="http://" Then 
		save_outfile fullpath
		fullpath="temp.png"
	End if
	dim strfilename, s, fso, f, intfilelength
	set fso = server.createobject("scripting.filesystemobject")
	if not fso.fileexists(Server.MapPath(fullpath)) then
		exit function
	end If
	set f = fso.getfile(Server.MapPath(fullpath))
	intfilelength = f.size
	set s = server.createobject("adodb.stream")
	s.open
	s.type = 1
	s.loadfromfile(Server.MapPath(fullpath))
	response.buffer = true
	response.clear
	'response.addheader "Content-Encoding","UTF-8" ' 乱码的解决方案
	'response.addheader "content-type","application/x-msdownload"
	response.addheader "content-disposition","attachment;filename=" & f.name
	response.addheader "content-length" ,intfilelength
	response.contenttype = "application/octet-stream"
	while not s.eos
		response.binarywrite s.read(1024 * 64)
		response.flush
	wend
	s.close
	set s = Nothing
	f.close
	set f = nothing
	downloadfile = true
end function
%>
