<%@LANGUAGE="VBSCRIPT"%> <%response.buffer=true%> <% strFileName = "files/file-18435.gif" strFilePath=server.mappath(strFilename)
set fso=createobject("scripting.filesystemobject") set f=fso.getfile(strfilepath) strFileSize = f.size set f=nothing: set fso=nothing Const adTypeBinary = 1 Response.Clear Set objStream = Server.CreateObject("ADODB.Stream") objStream.Open objStream.Type = adTypeBinary objStream.LoadFromFile strFilePath
StringToEncode=Lcase(strFileName)
ChooseTypeFile = GetMimeType(strFileName)
strFileType = ChooseTypeFile Response.AddHeader "Content-Disposition", "attachment; filename=" & strFileName Response.AddHeader "Content-Length", strFileSize Response.Charset = "UTF-8" Response.ContentType = strFileType Response.BinaryWrite objStream.Read Response.Flush objStream.Close Set objStream = Nothing End If
Function GetMimeType(strFileName) Dim ext, pos, str ext = LCase(strFileName) pos = InStr(1,ext,".",vbTextCompare) If pos > 0 Then ext = Mid(ext,pos+1)
Select Case ext Case "aif","aiff","aifc","cdda" str = "audio/aiff" Case "aim" str = "application/x-aim" Case "art" str = "image/x-jg" Case "au","snd" str = "audio/basic" Case "avi","vfw" str = "video/x-msvideo" Case "bmp" str = "image/bmp" Case "cdf" str = "application/x-cdf" Case "css" str = "text/css" Case "doc","dot","wiz","rtf" str = "application/msword" Case "exe" str = "application/x-msdownload" Case "fdf" str = "application/vnd.fdf" Case "gif" str = "image/gif" Case "hta" str = "application/hta" Case "htm","html" str = "text/html" Case "ico","icon" str = "application/x-icon" Case "ivf" str = "application/x-ivf" Case "jfif" str = "image/pjpeg" Case "jnlp" str = "application/x-java-jnlp-file" Case "jpg","jpeg","jpe" str = "image/jpeg" Case "js","jse" str = "text/javascript" Case "mdb" str = "application/msaccess" Case "mid","midi","rmi" str = "audio/mid" Case "mov","qt" str = "video/quicktime" Case "mpg","mp2","mpe","mpeg","m1v" str = "video/mpeg" Case "mp3" str = "audio/mpeg" Case "mp4" str = "video/mp4" Case "m3u" str = "audio/x-mpegurl" Case "pdf" str = "application/pdf" Case "png" str = "image/png" Case "pps","ppa","ppt","pot","pwz" str = "application/vnd.ms-powerpoint" Case "qtl" str = "video/x-quicktimeplayer" Case "ram","rmm" str = "audio/x-pn-realaudio" Case "rmf" str = "application/vnd.rmf" Case "rms" str = "audio/vnd.rn-realmedia-secure" Case "rmx" str = "audio/vnd.rn-realsystem" Case "rv" str = "audio/vnd.rn-realvideo" Case "ssm" str = "application/streamingmedia" Case "swf","spl" str = "application/futuresplash" Case "tif","tiff" str = "image/tiff" Case "txt","text" str = "text/plain" Case "wav","wave" str = "audio/wav" Case "wma" str = "audio/x-ms-wma" Case "wmp" str = "audio/x-ms-wmp" Case "wms" str = "audio/x-ms-wms" Case "wmv" str = "audio/x-ms-wmv" Case "wsc","sct" str = "text/scriptlet" Case "xfdf" str = "application/vnd.adobe.xfdf" Case "xls" str = "application/vnd.ms-excel" Case "xml","xsl" str = "text/xml" Case "zip","tar" str = "application/x-tar" Case "arc" str = "application/x-zip-compressed" Case Else str = "application/octet-stream" End Select
GetMimeType = str End Function %> |