R
robert
Hi,
I'm new to ASP but do know my way around VB and a bit of VB script. MY
ISP have ASP enabled for my website. So I'm pondering on how to write
an efficient script for users to download a few files from my website.
Having read posts on this and other newsgroups here's what I've got so
far. I have resorted to chop the download in chunks as it appears that
my ISP does not permit large files to be streamed out.
What I would like to know is if the code below can be made more
efficient (smaller or larger chunk size) or if there are some other
fundamental flaws I've overlooked.
Thanks,
Rob
<%
dim oFSO, oFile, objStream, strfilepath, filename
Const ForWriting = 2, ForAppending = 8
filename = Request.QueryString("file")
strFilePath=server.mappath("..\..\Bin\" & filename)
set fso=createobject("scripting.filesystemobject")
set f=fso.getfile(strfilepath)
strFileSize = f.size
set f=nothing: set fso=nothing
Const adTypeBinary = 1
Response.Clear
Response.Expires = 0
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath
strFileType = "application/exe"
Response.AddHeader "Content-Disposition", "attachment; filename=" &
filename
Response.AddHeader "Content-Length", strFileSize
Response.ContentType = strFileType
Dim NumberofBlocks, chunk, lBlocks, fsize
fsize = strFileSize
sentbytes = 0
chunk = 16384
NumberofBlocks=(strFileSize -(strFileSize mod chunk))/chunk
For lBlocks = 1 To NumberofBlocks
If Response.IsClientConnected = False Then Exit For
Response.BinaryWrite objStream.Read(CHUNK)
Response.Flush
' sentbytes = sentbytes + chunk
Next
strFileSize = strFileSize Mod CHUNK
If strFileSize > 0 And Response.IsClientConnected = True Then
Response.BinaryWrite objStream.Read(strFileSize)
Response.Flush
' sentbytes = sentbytes + strFileSize
end if
objStream.Close
set objStream = Nothing
Set objFile = Nothing
'response.end
%>
I'm new to ASP but do know my way around VB and a bit of VB script. MY
ISP have ASP enabled for my website. So I'm pondering on how to write
an efficient script for users to download a few files from my website.
Having read posts on this and other newsgroups here's what I've got so
far. I have resorted to chop the download in chunks as it appears that
my ISP does not permit large files to be streamed out.
What I would like to know is if the code below can be made more
efficient (smaller or larger chunk size) or if there are some other
fundamental flaws I've overlooked.
Thanks,
Rob
<%
dim oFSO, oFile, objStream, strfilepath, filename
Const ForWriting = 2, ForAppending = 8
filename = Request.QueryString("file")
strFilePath=server.mappath("..\..\Bin\" & filename)
set fso=createobject("scripting.filesystemobject")
set f=fso.getfile(strfilepath)
strFileSize = f.size
set f=nothing: set fso=nothing
Const adTypeBinary = 1
Response.Clear
Response.Expires = 0
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath
strFileType = "application/exe"
Response.AddHeader "Content-Disposition", "attachment; filename=" &
filename
Response.AddHeader "Content-Length", strFileSize
Response.ContentType = strFileType
Dim NumberofBlocks, chunk, lBlocks, fsize
fsize = strFileSize
sentbytes = 0
chunk = 16384
NumberofBlocks=(strFileSize -(strFileSize mod chunk))/chunk
For lBlocks = 1 To NumberofBlocks
If Response.IsClientConnected = False Then Exit For
Response.BinaryWrite objStream.Read(CHUNK)
Response.Flush
' sentbytes = sentbytes + chunk
Next
strFileSize = strFileSize Mod CHUNK
If strFileSize > 0 And Response.IsClientConnected = True Then
Response.BinaryWrite objStream.Read(strFileSize)
Response.Flush
' sentbytes = sentbytes + strFileSize
end if
objStream.Close
set objStream = Nothing
Set objFile = Nothing
'response.end
%>