file_down.asp

来自「使用Asp+Access+FSO+Jmail+Servu开发」· ASP 代码 · 共 59 行

ASP
59
字号
<!--#include file="chkuser.asp"-->
<!--#include file="config.asp"-->
<!--#include file="inc/user.asp"-->
<%
path=Request("path")
If path = "" or Instr(path,"..")>0 then
response.redirect("../error.asp?error=baderror")
Response.end
End if
checkpath="/"&Request.Cookies("username")
if lcase(checkpath)<>lcase(left(path,len("/"&Request.Cookies("username")))) then
response.redirect("../error.asp?error=baderror")
response.end
end if
call downloadFile(path)
function downloadFile(strFile)
	strFilename = userdir&strFile
	Response.Buffer = True
	Response.Clear
	
	Set s = Server.CreateObject("ADODB.Stream")
	s.Open
	
	s.Type = 1
	
	on error resume next
	
	
	if not fso.FileExists(strFilename) then
		Response.Write("<h1>Error:</h1>" & strFilename & " does not exist<p>")
		Response.End
	end if
	
	
	Set f = fso.GetFile(strFilename)
	intFilelength = f.size
	
	
	s.LoadFromFile(strFilename)
	if err then
		Response.Write("<h1>Error: </h1>" & err.Description & "<p>")
		Response.End
	end if
	
	Response.AddHeader "Content-Disposition", "attachment; filename=" & f.name
	Response.AddHeader "Content-Length", intFilelength
	Response.CharSet = "UTF-8"
	Response.ContentType = "application/octet-stream"
	
	Response.BinaryWrite s.Read
	Response.Flush
	
	
	s.Close
	Set s = Nothing
	
	
End Function 
%> 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?