﻿<%
Response.Buffer = True 
strFileName=request("thefile")
strFileLocation = server.mappath(strFileName)

Const adTypeBinary = 1 

Set objStream = Server.CreateObject("ADODB.Stream") 
objStream.Open 
objStream.Type = adTypeBinary 
objStream.LoadFromFile strFileLocation
strFileType = lcase(Right(strFileLocation, 4)) 
Select Case strFileType 
Case ".asf" 
ContentType = "video/x-ms-asf" 
Case ".avi" 
ContentType = "video/avi" 
Case ".f4v" 
ContentType = "video/mp4" 
Case ".mp4" 
ContentType = "video/mp4" 
Case ".swf" 
ContentType = "application/x-shockwave-flash" 
Case ".flv" 
ContentType = "flv-application/octet-stream" 
'ContentType = "video/x-flv" 
Case ".doc" 
ContentType = "application/msword" 
Case ".zip" 
ContentType = "application/zip" 
Case ".xls" 
ContentType = "application/vnd.ms-excel" 
Case ".gif" 
ContentType = "image/gif" 
Case ".jpg", "jpeg" 
ContentType = "image/jpeg" 
Case ".wav" 
ContentType = "audio/wav" 
Case ".mp3" 
ContentType = "audio/mpeg3" 
Case ".mpg", "mpeg" 
ContentType = "video/mpeg" 
Case ".rtf" 
ContentType = "application/rtf" 
Case ".htm", "html" 
ContentType = "text/html" 
Case ".asp" 
ContentType = "text/asp" 
Case ".pdf" 
ContentType = "application/pdf" 
Case Else 
ContentType = "application/octet-stream" 
End Select 

thearr=split(strFileName,"/")
thename=thearr(ubound(thearr))
Response.AddHeader "Content-Disposition", "attachment; filename=" & thename 
Response.Charset = "UTF-8" 
Response.ContentType = ContentType 
Response.BinaryWrite objStream.Read 
Response.Flush 
objStream.Close 
Set objStream = Nothing 
%>