asp download file

Print Friendly, PDF & Email

Response.BinaryWrite Office 2007 docs corrupted

<%
file_name = REQUEST("FILE_NAME")  '다운받을 파일명
strFilePath ="D:\WebSite\DCS\" & file_name '경로
URL = strFilePath

  Dim fso, msg
  Set fso = CreateObject("Scripting.FileSystemObject")

 If (fso.FileExists(URL)) Then
 strName2= Mid(file_name,InstrRev(file_name, ".")+1)
 
strName1 = UCase(trim(strName2))

if strName1 = "EXE" or strName1 ="exe"  then

URL = "../DCS/" & file_name
Response.Redirect URL

else if  strName1  = "asp" or strName1  = "ASP" or strName1  = "INC" or  strName1 ="inc" then

response.redirect "../Error.asp?ERROR=500&EI=UPLOAD"

else

    Select case strName1
		case "DOC"
		   Response.ContentType = "application/vnd.ms-word"
		case "DOCX"
		   Response.ContentType = "application/vnd.ms-word"
		case "XLSX"
			Response.ContentType = "application/vnd.ms-excel"
		case "XLS"
			Response.ContentType = "application/vnd.ms-excel"
		Case Else
			Response.ContentType = "application/unknown"
	end Select
	
    Response.AddHeader "Content-Disposition","attachment; filename=" &file_name

    Set objStream = Server.CreateObject("ADODB.Stream")

    objStream.Open
    objStream.Type = 1

    objStream.LoadFromFile URL
     download = objStream.Read
    Set objstream = nothing

    Response.BinaryWrite download

end if
end if
else
 response.write "파일이 존재 하지 않습니다."
end if
%>

참조 : http://www.aspsnippets.com/Articles/Save-Files-to-SQL-Server-Database-using-FileUpload-Control.aspx

다운로드시 10M 이상 다운로드 안될때 // IIS 서비스 재시작
C:\WINDOWS\system32\inetsrv
MetaBase.xml 열어 MetaBase수정 (범퍼/업로드)

AspBufferingLimit=”10240000″ => AspBufferingLimit=”20240000″
AspMaxRequestEntityAllowed=”4240000″ => spMaxRequestEntityAllowed=”20240000″