สวัสดีครับ ผม มีโค้ด ASP สำหรับการ ดาวโหลด ไฟล์ จาก Web server ดังนี้
Code (ASP)
<%@Language="VBScript"%>
<%Option Explicit%>
<%Response.Buffer = true%>
<%
On Error Resume Next
Dim strPath
'Response.Buffer = False
Server.ScriptTimeout = 3000000
'-----------
'Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
'adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
'Set aspSection = adminManager.GetAdminSection("system.webServer/asp", "MACHINE/WEBROOT/APPHOST")
'Set limitsElement = aspSection.ChildElements.Item("limits")
'limitsElement.Properties.Item("scriptTimeout").Value = "00:02:00"
'limitsElement.Properties.Item("queueConnectionTestTime").Value = "00:00:05"
'limitsElement.Properties.Item("requestQueueMax").Value = 1000
'limitsElement.Properties.Item("maxRequestEntityAllowed").Value = 2147483647
'adminManager.CommitChanges()
'-----------
strPath ="test1.exe"'CStr(Request.QueryString("file"))exe'-- do some basic error checking for the QueryString
If strPath = "" Then
Response.Clear
Response.Write("No file specified.")
Response.End
ElseIf InStr(strPath, "..") > 0 Then
Response.Clear
Response.Write("Illegal folder location.")
Response.End
ElseIf Len(strPath) > 1024 Then
Response.Clear
Response.Write("Folder path too long.")
Response.End
Else
Call DownloadFile(strPath)
End If
Private Sub DownloadFile(file)
'--declare variables
Dim strAbsFile
Dim strFileExtension
Dim objFSO
Dim objFile
Dim objStream
'-- set absolute file location
strAbsFile = Server.MapPath(file)
'-- create FSO object to check if file exists and get properties
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strAbsFile) Then
Set objFile = objFSO.GetFile(strAbsFile)
'-- first clear the response, and then set the appropriate headers
'Response.Flush()
Response.Clear
'-- the filename you give it will be the one that is shown
' to the users by default when they save
Response.AddHeader "Content-Disposition", "attachment; filename=" & objFile.Name
Response.AddHeader "Content-Length", objFile.Size
Response.Buffer = true
Response.ContentType = "application/octet-stream"
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
'-- set as binary
objStream.Type = 1
Response.CharSet = "UTF-8"
'-- load into the stream the file
objStream.LoadFromFile(strAbsFile)
'objStream.SaveToFile strAbsFile,"C:\EndoSMART1\test.exe"
'-- send the stream in the response
'Response.BinaryWrite(objStream.Read)
Do While Not objStream.EOS
Response.BinaryWrite objStream.Read(3670016)
Response.Flush
Loop
objStream.Close
Set objStream = Nothing
Set objFile = Nothing
Else 'objFSO.FileExists(strAbsFile)
Response.Clear
Response.Buffer = False
Response.Write("No such file exists.")
End If
Set objFSO = Nothing
End Sub
%>