Simple Download Method with Streams
Enables you to put a certain degree of protection in files available for download in you IIS Server by making them inaccessible by a direct URL. Hides them in other directory, out of wwwroot.
Original Author: Daniel Verzellesi
Inputs
Pass the file name.
Returns
Get the file written in binary format into Request.
Code
<%
'-- DOWNLOAD.ASP
'
'-- Simple Download Method with Streams
' Daniel Verzellesi
'
' As an example I'm getting the file I want to download
' from the Request (//.../dowload.asp?fname=myfile1.doc).
' You can change it to get the file name from a DB or
' anything else...
'
Dim p, st, f
'-- my "secret" path
p = "c:files"
'-- file name
f = Request.QueryString("fname")
'-- get file into stream
Set st = CreateObject("ADODB.Stream")
st.Open
st.Type = 1 'binary
st.LoadFromFile p & f
'-- send stream to response
Response.ContentType = "application/my-download"
Response.AddHeader "Content-Disposition", "attachment; filename=""" & f & """"
Response.BinaryWrite st.Read(-1) 'read all
Response.End
'-- close the stream
set st = nothing
%>
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.