Just fell across this article on Forcing a Download. I really wish to be able to give an option to download a video I have stored on my site. Here are the conditions of my site:
download.asp is stored in folder ipod
videos are stored in ipod/videos/download
when I visit: ipod/download.asp?filename=ClockInOutEnglish_Subs.m4v to download ClockInOutEnglish_Subs.m4v, I get the following:
The website cannot display the page
HTTP 500
Most likely causes:
The website is under maintenance.
The website has a programming error.
Here is the code I'm using:
<%
'=======================
'Define the names of your functions
'=======================
Dim Stream
Dim Contents
Dim FileName
Dim FileExt
Const adTypeBinary = 1
'=======================
'Get the actual file name from the URL that is passed to the browser
'=======================
FileName = request.querystring("filename") 'Get the name from the URL
'=======================
'GIVE AN ERROR MESSAGE IF THE URL IS EMPTY
'=======================
if FileName = "" Then
response.write "Filename Not specified."
response.end
end if
'=======================
'prevent access to certain files
'=======================
FileExt = Mid(FileName, InStrRev(FileName, ".") + 1)
select case UCase(FileExt)
Case <> "M4V"
response.write "You cannot access these file types."
response.end
end select
'=======================
'Start the download process if all is good
'=======================
response.clear
response.contentType = "application/octet-stream"
response.addheader "content-disposition", "attachment; filename=" & FileName
set stream = server.CreateObject("ADODB.Stream")
stream.type = adTypeBinary
stream.open
stream.LoadFromFile Server.MapPath("/video/download") & FileName
while not stream.EOS
response.BinaryWrite Stream.Read(1024 * 64)
wend
stream.Close
Set stream = Nothing
response.Flush
response.End
%>