home *** CD-ROM | disk | FTP | other *** search
/ 207.233.110.77 / 207.233.110.77.tar / 207.233.110.77 / vbasic / startDownload.asp < prev    next >
Text File  |  2001-10-02  |  3KB  |  97 lines

  1. <%@ LANGUAGE="VBSCRIPT" %>
  2. <% Option Explicit %>
  3. <!-- METADATA 
  4.    TYPE="TypeLib" 
  5.    FILE="C:\Program Files\Common Files\System\ADO\msado21.tlb" 
  6. -->
  7. <!--#include file="DatabaseConnect.asp"-->
  8. <!--#include file="Crypt-DeCrypt.asp"-->
  9. <% 
  10. If Session("ValidatedStudent") <> True Then
  11.     Response.Redirect "error.asp?error=denied"
  12. End If 
  13.  
  14.     '8***********************************************8
  15.     ' Jason Withrow - For ASP101 July 2001
  16.     ' This page forces the save as dialogue to prevent
  17.     ' files from being opened in the browser.
  18.     '
  19.     ' jwithrow@mediaone.net
  20.     '8***********************************************8
  21.  
  22. Response.Buffer = True
  23. Dim strFilePath
  24. Dim strFileSize 
  25. Dim strFileName
  26. Dim strFileType
  27. Dim objStream
  28. Dim ContentType
  29.  
  30. Const adTypeBinary = 1
  31.  
  32. strFilePath = Decrypt(Request.QueryString("File"))
  33. strFileSize = Request.QueryString("Size")
  34. strFileName = Request.QueryString("Name")
  35.  
  36. Response.Clear
  37.  
  38. '8*******************************8
  39. ' Requires MDAC 2.5 to be stable
  40. ' I recommend MDAC 2.6 or 2.7
  41. '8*******************************8
  42. Set objStream = Server.CreateObject("ADODB.Stream")
  43. objStream.Open
  44. objStream.Type = adTypeBinary
  45. objStream.LoadFromFile strFilePath
  46.  
  47. strFileType = lcase(Right(strFileName, 4))
  48.     
  49.     ' Feel Free to Add Your Own Content-Types Here
  50.     Select Case strFileType
  51.         Case ".asf"
  52.             ContentType = "video/x-ms-asf"
  53.         Case ".avi"
  54.             ContentType = "video/avi"
  55.         Case ".doc"
  56.             ContentType = "application/msword"
  57.         Case ".zip"
  58.             ContentType = "application/zip"
  59.         Case ".xls"
  60.             ContentType = "application/vnd.ms-excel"
  61.         Case ".gif"
  62.             ContentType = "image/gif"
  63.         Case ".jpg", "jpeg"
  64.             ContentType = "image/jpeg"
  65.         Case ".wav"
  66.             ContentType = "audio/wav"
  67.         Case ".mp3"
  68.             ContentType = "audio/mpeg3"
  69.         Case ".mpg", "mpeg"
  70.             ContentType = "video/mpeg"
  71.         Case ".rtf"
  72.             ContentType = "application/rtf"
  73.         Case ".htm", "html"
  74.             ContentType = "text/html"
  75.         Case ".asp"
  76.             ContentType = "text/asp"
  77.         Case Else
  78.             'Handle All Other Files
  79.             ContentType = "application/octet-stream"
  80.     End Select
  81.     
  82.     
  83.     Response.AddHeader "Content-Disposition", "attachment; filename=" & strFileName
  84.     Response.AddHeader "Content-Length", strFileSize
  85.     ' In a Perfect World, Your Client would also have UTF-8 as the default 
  86.     ' In Their Browser
  87.     Response.Charset = "UTF-8"
  88.     Response.ContentType = ContentType
  89.     
  90.     Response.BinaryWrite objStream.Read
  91.     Response.Flush
  92.  
  93. objStream.Close
  94. Set objStream = Nothing
  95.  
  96. %>
  97.