Date:  02/24/2006 08:08:36 PM Msg ID:  002850
From:  FoxWeb Support Thread:  002845
Subject:  Re: Corrupted file when downloading
It also seems like the large content size may be causing timing problems.  Try sending the file in chunks:
 

<%
cfile = request.item('cFile')
IF not empty(cfile)
  * A file was selected in the form
  Response.Buffer = .T.
  FileName = alltrim(cfile)
  FileExtension = UPPER(JustExt(FileName))
  * Verify that the file exists and is one of the authorized types
  IF FILE(FileName)
    * The content type must be changed in order to prevent browsers from displaying certain file types
    ContentType = "application/unknown"
    * Specify file name
    Response.AddHeader("Content-Disposition", "attachment; filename=" + cFile)
    * Read contents of file into string
    FileContent = ReadFile(FileName)
    * Specify size so that progress bar works properly
    Response.AddHeader("Content-Length", Server.ToString(LEN(FileContent)))
    Response.ContentType = ContentType
    * Send file to browser in chunks of 5 MB
    M.ChunkSize = 5000000
    FOR M.CurChunk = 1 TO CEILING(LEN(M.FileContent) / M.ChunkSize)

      * Make sure that the script won't time out
      Server.AddScriptTimeout(5, .T.)

      * Send the next chunk
      Response.Write(SUBSTR(M.FileContent, ((M.CurChunk - 1) * M.ChunkSize) + 1, M.ChunkSize))
      Response.Flush
    NEXT
  ELSE
    %>
    <html>
      <head>
        <title>Error!</title>
      </head>
      <body>
        Selected file does not exist, please contact IT Support
      </body>
    </html>
    <%
  ENDIF
ENDIF
%>

FoxWeb Support Team
support@foxweb.com email

Sent by Ali Koumaiha on 02/21/2006 07:25:47 AM:
I am using the example provided download.fwx, and i made minor modifications.  I am having 2 problems:
 
1- Files being downloaded are corrupted.  For example, if i have a small zip file 300K which opens prior to downloading, after it is downloaded via the method/code below, i cannot open the file again.  I tried it with XLS file, BMP file, JPG file, etc..
 
2- Files that are over 15MB will not download.  I have a file that is 20MB on a LAN (Basically my app is running on the lan), using the method below, the browser IE6 prompts for Save/Open.  When i click save, it acts as if its about to download, and after like 3 minutes or saw, i get a messagebox from IE "Server was reset or something like...etc.."
 
Do i have to put the files in a the root/accessible and just pass a link to the user?
 
I really want to use a script to do that.  What are my options.
 
thanks in advance.
 

<html>
<%
   cfile = request.item('cFile')
  
IF not empty(cfile)
 * A file was selected in the form
 Response.Buffer = .T.
 FileName = alltrim(cfile)
 FileExtension = UPPER(JustExt(FileName))
 * Verify that the file exists and is one of the authorized types
 IF FILE(FileName)
  * The content type must be changed in order to prevent browsers from displaying certain file types
  ContentType = "application/unknown"
  * Specify file name
  Response.AddHeader("Content-Disposition", "attachment; filename=" + cFile)
  
  * Read contents of file into string
  FileContent = ReadFile(FileName)
  * Specify size so that progress bar works properly
  Response.AddHeader("Content-Length", Server.ToString(LEN(FileContent)))
  Response.ContentType = ContentType
  Response.Buffer = .T.
  * Send file to browser
  Response.Write(FileContent)
  response.end
 ELSE
  response.write("Selected file does not exist, please contact IT Support")
  response.end
 ENDIF
ENDIF

Endfunc
%>
</html>