| | |
Problem Downloading large files
Please support our ASP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: May 2004
Posts: 1
Reputation:
Solved Threads: 0
Currently, users can download mps files from my website PROVIDED the files are relatively small. With large files (4 mega), the files do not download. I undestand that large files must be downloaded in blocks. How does one do this??
My current code reads as follows:
<%
Set filesys = CreateObject("Scripting.FileSystemObject")
strWav = "/media/"&Request.Form("code1")&Request.Form("code2")&Request.Form("code3")&".mp3"
strFilename = server.MapPath(strWav)
if request.form("code1") = "" OR len(request.form("code1")) <5 OR request.form("code2") = "" OR len(request.form("code2")) <4 OR request.form("code3") = "ER" Then
response.write "<b><p align = center> <font color=" & "#FF0000" & ">Please enter all required fields. Be sure to enter the correct number of digits.</b></font>"
else
If filesys.FileExists(strFilename) Then
strFilename = server.MapPath(strWav)
Response.Buffer = True
Response.Clear
Set s = Server.CreateObject("ADODB.Stream")
s.Open
s.Type = 1
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(strFilename)
intFilelength = f.size
s.LoadFromFile(strFilename)
Response.AddHeader "Content-Disposition", "attachment; filename=" & f.name
Response.AddHeader "Content-Length", intFilelength
Response.Charset = "UTF-8"
Response.ContentType = "application/octet-stream"
Response.BinaryWrite s.Read
Response.Flush
s.Close
Set s = Nothing
Else
response.write "<b><p align = center><font color=" & "#FF0000" & ">Sorry, your file is not yet prepared or else you entered the wrong name and number codes.</b></font>"
End If
End If
%>
My current code reads as follows:
<%
Set filesys = CreateObject("Scripting.FileSystemObject")
strWav = "/media/"&Request.Form("code1")&Request.Form("code2")&Request.Form("code3")&".mp3"
strFilename = server.MapPath(strWav)
if request.form("code1") = "" OR len(request.form("code1")) <5 OR request.form("code2") = "" OR len(request.form("code2")) <4 OR request.form("code3") = "ER" Then
response.write "<b><p align = center> <font color=" & "#FF0000" & ">Please enter all required fields. Be sure to enter the correct number of digits.</b></font>"
else
If filesys.FileExists(strFilename) Then
strFilename = server.MapPath(strWav)
Response.Buffer = True
Response.Clear
Set s = Server.CreateObject("ADODB.Stream")
s.Open
s.Type = 1
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(strFilename)
intFilelength = f.size
s.LoadFromFile(strFilename)
Response.AddHeader "Content-Disposition", "attachment; filename=" & f.name
Response.AddHeader "Content-Length", intFilelength
Response.Charset = "UTF-8"
Response.ContentType = "application/octet-stream"
Response.BinaryWrite s.Read
Response.Flush
s.Close
Set s = Nothing
Else
response.write "<b><p align = center><font color=" & "#FF0000" & ">Sorry, your file is not yet prepared or else you entered the wrong name and number codes.</b></font>"
End If
End If
%>
•
•
Join Date: Jul 2004
Posts: 32
Reputation:
Solved Threads: 1
I always use these 2 functions:-
Hope they help you.
ASP Syntax (Toggle Plain Text)
Sub ForceDownload(strFilePath) Set oFS = Server.CreateObject("Scripting.FileSystemObject") Set oFile = oFS.GetFile(strFilePath) StrFileSize = oFile.Size Set oFile = Nothing Set oFS = Nothing Const adTypeBinary = 1 Set objStream = Server.CreateObject("ADODB.Stream") objStream.Open objStream.Type = adTypeBinary objStream.LoadFromFile strFilePath strFileType = lcase(Right(strFilePath, 4)) ' Feel Free to Add Your Own Content-Types Here Select Case strFileType 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 ".wav" ContentType = "audio/wav" Case ".mp3" ContentType = "audio/mpeg3" Case ".mpg", "mpeg" ContentType = "video/mpeg" Case ".rtf" ContentType = "application/rtf" Case ".htm", "html" ContentType = "text/html" Case ".asp" ContentType = "text/asp" Case ".pdf" ContentType = "application/pdf" Case Else 'Handle All Other Files ContentType = "application/octet-stream" End Select Response.AddHeader "Content-Disposition", "attachment; filename=" & StripFileName(StrFilePath) Response.AddHeader "Content-Length", strFileSize ' In a Perfect World, Your Client would also have UTF-8 as the default ' In Their Browser Response.Charset = "UTF-8" Response.ContentType = ContentType Response.BinaryWrite objStream.Read Response.Flush objStream.Close Set objStream = Nothing End Sub function StripFileName(ByVal asPath) if asPath = "" Then Exit function asPath = Replace(asPath, "/", "\") if InStr(asPath, "\") = 0 Then Exit function if Right(asPath, 1) = "\" Then Exit function StripFileName = Right(asPath, Len(asPath) - InStrRev(asPath, "\")) End function
Hope they help you.
![]() |
Similar Threads
- downloading very large files with PHP (PHP)
- Problem with My Project (Missing Files) (Visual Basic 4 / 5 / 6)
- dedicated bandwidth? (Networking Hardware Configuration)
- Problem downloading from the net (Viruses, Spyware and other Nasties)
- PHP for large files (PHP)
- Reading Large Files (Java)
- how to open large files not supported by aol (Windows 95 / 98 / Me)
- downloading / streaming through firewall (OS X)
Other Threads in the ASP Forum
- Previous Thread: RDS Issue in Internet Explorer
- Next Thread: CDONTS email goes directly to Badmail folder
| Thread Tools | Search this Thread |
archive asp asp.net aspandmssqlserver2005 aspandmssqlserver2005connection aspconnection connection database databaseconnection dreamweaver excel fso iis msmsql mssql2005 mssqlserver2005 mssqlserver2005andasp mssqlserverandasp opentextfile record searchbox selectoption single specfic sqlserver sqlserverconnection windows7





