<%
Response. Buffer = true
Response. Clear
Dim URL
Dim FSO, FL, flsize
Dim dname
Dim objstream, contenttype, flname, isre, url1
Dim strfilename
Strfilename = Replace (replace (Request ("file "), "/", ""), "/", "")'
Change strfilename = "/files/" & strfilename 'to the storage path of your file.
If strfilename <> "" then
* Download the server directory where the file is stored.
Url = server. mappath (strfilename)
Else
Response. Write ("No found ")
Response. End
End if
Set FSO = server. Createobject ("scripting. FileSystemObject ")
Set FL = FSO. GetFile (URL)
Flsize = fL. Size
Flname = fL. Name
Set FL = nothing
Set FSO = nothing
Set objstream = server. Createobject ("ADODB. Stream ")
Objstream. Open
Objstream. type = 1
Objstream. loadfromfile URL
Select case lcase (right (flname, 4 ))
Case ". ASF"
Contenttype = "Video/X-MS-ASF"
Case ". Avi"
Contenttype = "Video/Avi"
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 ". BMP"
Contenttype = "image/BMP"
Case ". ppt"
Contenttype = "application/vnd. MS-PowerPoint"
Case ". mdb"
Contenttype = "application/X-msaccess"
Case ". wav"
Contenttype = "audio/WAV"
Case ". MP3"
Contenttype = "audio/mpeg3"
Case ". mpg", "MPEG"
Contenttype = "Video/MPEG"
Case ". rtf"
Contenttype = "application/rtf"
Case ". htm", "html", "htm (1 )"
Contenttype = "text/html"
Case ". txt"
Contenttype = "text/plain"
Case else
Contenttype = "application/octet-stream"
End select
'I uploaded it using the Upload Component. If the name is duplicated, the suffix "(number)" is generated,
'The some hosts will block this type of files from being downloaded, so add a check here to apply the suffix automatically generated by the Upload Component
If instr (lcase (right (flname, 1), ")") then
Flname = mid (flname, 1, Len (flname)-3)
End if
Response. addheader "content-disposition", "attachment; filename =" & flname
Response. addheader "Content-Length", flsize
Response. charset = "UTF-8"
Response. contenttype = contenttype
Response. binarywrite objstream. Read
Response. Flush
Response. Clear ()
Objstream. Close
Set objstream = nothing
%>