Upload - upload with ie-style progress bar.

          Sample for ScriptUtils.ASPForm.getForm 

Examples
Upload - upload with ie-style progress bar. 
<%
'Sample file progress.asp 
'Upload files with simple progress bar.

Server.ScriptTimeout = 200
'Sample file Field-Name.asp 
'Enumerate all source fields and write its names 
Dim Form: Set Form = Server.CreateObject("ScriptUtils.ASPForm")

If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
  Form.SizeLimit = 1000000000
  Form.TempPath = "Z:\Temp"
  
  'Set the upload ID for this form.
  'Progress bar window will receive the same ID.
  Form.UploadID = Request.QueryString("UploadID")'

  'was the Form successfully received?
  If Form.State = 0 Then
    'Do something with upload - save, enumerate, ...
    Response.Write "<br><b>Upload result: Form was accepted.</b>" 
    Response.Write "<br>Number of file fields:" & Form.Files.Count
    Response.Write "<br>Request total bytes:" & Request.TotalBytes
    
  End If
End If


'get an unique upload ID for this upload script and progress bar.
Dim UploadID, PostURL
UploadID = Form.NewUploadID

'Send this ID as a UploadID QueryString parameter to this script.
PostURL = Request.ServerVariables("SCRIPT_NAME") & "?UploadID=" & UploadID'

%>  
<br>sample For <A Href=http://www.motobit.com>HugeASP upload</A>
<br>Upload files with simple progress bar.
<form name="file_upload" method="POST" ENCTYPE="multipart/form-data" OnSubmit="return ProgressBar();" Action="<%=PostURL%>">

<Div ID=files>
   File 1 : <input type="file" name="File1"><br>
   File 2 : <input type="file" name="File2"><br>
   File 3 : <input type="file" name="File3">
</Div>

<Input Type=Button Value="Add a file" OnClick=return(Expand()) 
 Style="border=0;background=yellow;cursor:hand"><br>

Description:<input Name=Description1 Size=60><br>
<input Name=SubmitButton Value="Submit »" Type=Submit><br>
</Form>

<SCRIPT>
//Open window with progress bar.
Function ProgressBar(){
  var ProgressURL
  ProgressURL = 'ieprobar.asp?UploadID=<%=UploadID%>'

  var v = window.open(ProgressURL,'_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=350,height=200')
  
  return true;
}//
</SCRIPT> 

<Script>
//Expand form with a New File fields If needed.
var nfiles = 3;
Function Expand(){
  nfiles++
  var adh = '<BR> File '+nfiles+' : <input type="file" name="File'+nfiles+'">';
  files.insertAdjacentHTML('BeforeEnd',adh);
  return false;
}
</Script>



<%@EnableSessionState=False%>
<%
'Sample file ieprobar.asp 
'Session must be off to work correctly.
'Simple IE-style progress bar for upload script.

  Server.ScriptTimeout = 10
  Dim Form: Set Form = CreateObject("ScriptUtils.ASPForm")
  
  'Get current uploading form with UploadID.
  On Error Resume Next
  Set Form = Form.getForm(Request.QueryString("UploadID"))'
  
  If Err = 0 Then '?Completted 0 = in progress
    On Error Goto 0
    If Form.BytesRead>0 Then'Upload was started.
      'enumerate uploaded fields.
      'and build report about its current state.
      Dim fHTML, Field
      For Each Field In Form.Files
        'Get field name
        fHTML = fHTML & "FieldName:" & Field.Name
        
        If Field.InProgress Then
          'this field is in progress now.
          fHTML = fHTML & ", uploading: " & Field.FileName
        ElseIf Field.Length>0 Then
          'This field was succefully uploaded.
          fHTML = fHTML & ", OK: " & Field.FileName & "," & FormatSize(Field.Length)
        End If
        
        fHTML = fHTML & "<br>"
      Next
    End If

  'Do not cache output data of this script.
  Response.CacheControl = "no-cache"
  Response.AddHeader "Pragma","no-cache"
  
  'This script is progress bar.
  'There is a good idea to refresh it to show progress more than once :-).
  'Refresh time is in second
  Response.AddHeader "Refresh", "1"

  'Count progress indicators
  ' - percent and total read, total bytes, etc.
  Dim PercBytesRead, PercentRest, BytesRead, TotalBytes
  Dim UploadTime, RestTime, TransferRate
  BytesRead = Form.BytesRead
  TotalBytes = Form.TotalBytes

  If TotalBytes>0 Then 
    'upload started.
    PercBytesRead = Int(100*BytesRead/TotalBytes)
    PercentRest = 100-PercBytesRead
    
    If Form.ReadTime>0 Then TransferRate = BytesRead / Form.ReadTime
    If TransferRate>0 Then RestTime = FormatTime((TotalBytes-BytesRead) / TransferRate) 
    TransferRate = FormatSize(1000 * TransferRate)
  Else
    'upload not started.
    RestTime = "?"
    PercBytesRead = 0
    PercentRest = 100
    TransferRate = "?"
  End If

  'Create graphics progress bar.
  'The bar is created with blue (TDsread, completted) / blank (TDsRemain, remaining) TD cells.
  Dim TDsread, TDsRemain
  TDsread = Replace(Space(0.5*PercBytesRead), " ", "<TD BGColor=blue Class=p> </TD>")
  TDsRemain = Replace(Space(0.5*PercentRest), " ", "<TD Class=p> </TD>")

  'Format output values.
  UploadTime = FormatTime(Form.ReadTime)
  TotalBytes = FormatSize(TotalBytes)
  BytesRead = FormatSize(BytesRead)

'Simple utilities.
'Formats milisedond to m:ss format.
Function FormatTime(byval ms)
  ms = 0.001 * ms 'get second
  FormatTime = (ms \ 60) & ":" & Right("0" & (ms Mod 60),2) & "s"
End Function 

'Format bytes to a string
Function FormatSize(byval Number)
  If IsNumeric(Number) Then
    If Number > &H100000 Then'1M
      Number = FormatNumber (Number/&H100000,1) & "MB"
    ElseIf Number > 1024 Then'1k
      Number = FormatNumber (Number/1024,1) & "kB"
    Else
      Number = FormatNumber (Number,0) & "B"
    End If
  End If
  FormatSize = Number
End Function

'Some comments for HTML
'Page-Enter and revealTrans is for Flicker-Free progress.

%>
<HTML>
<Head>
 <style type='text/css'>
  BODY{font-size:10pt}
  TD{font-size:9pt} 
  TD.p{font-size:6px;Height:6px;border:1px inset white}
 </style>
 <meta http-equiv="Page-Enter" content="revealTrans(Duration=0,Transition=6)"> 
 <Title>Upload progress</Title>
</Head>

<Body BGcolor=Silver LeftMargin=15 TopMargin=4 RIGHTMARGIN=4 BOTTOMMARGIN=4>

Uploading:<br> <%=TotalBytes%> To <%=Request.ServerVariables("HTTP_HOST")%> ...<br>
<Table cellpadding=0 cellspacing=0 border=0 width=100% >
<tr>
 <%=TDsread%><%=TDsRemain%>
</tr>
</table>

<Table cellpadding=0 cellspacing=0 border=0>
<tr>
 <Td>Estimated Time left:</td>
 <Td> <%=RestTime%> (<%=BytesRead%> of <%=TotalBytes%> received)</Td>
</tr>
<tr>
 <Td>TransferRate:</td>
 <Td> <%=TransferRate%>/s</Td>
</tr>
<tr>
 <Td>Upload time:</td>
 <Td> <%=UploadTime%> (<%=PercBytesRead%>%)</Td>
</tr>
</table>

<br><Center><Input Type=Button Value="Cancel upload" OnClick="Cancel()" Style="background=silver;cursor:hand"></Center>
<br>

<%=fHTML%>

<Script>
Function Cancel(){
	opener.document.location = opener.document.location  + '&Action=Cancel';
	window.close();
}
</Script>

</Body>
</HTML>

<%
Else 'if Err = 0 then upload completted
%>
<HTML>
 <HEAD>
 <TITLE>Upload Finished</TITLE>
 <Script>window.close();</Script>
 </HEAD>
</HTML>
<%
End If'if Err = 0 then 
%>
  Other links for Upload - upload with ie-style progress bar.
The ASPForm collection retrieves the values of form elements posted to ASP script by a form using the POST method. ASPForm can process multipart/form-data or application/x-www-form-urlencoded data with length up to 2GB.
      Easy to use, hi-performance ASP file upload component with progress bar indicator. Let's you upload multiple files with size up to 2GB to a disk or database along with another form fields. Works with large posts, any character set (including unicode utf-8). Contains one-click multiple files/folders download with on-the-fly compression (Using BinaryWrite/BinaryRead).
      Hi-performance text file logging for ASP/VBScript/VBA applications. Lets you create daily/weekly/monthly log files with variable number of logged values and extra timing and performance info.
       Lets you work with safearray binary data in VBS/JS. It also enables conversion between binary and String data using several code pages. ZLib compress and uncompress functions. Lets you transfer files using compressed stream from a client to server using IE.
      This library also enables calling of some Kernel and Advapi functions (performance, timing, sleep, configuration ...) and enables native work with INI files.


© 1996 – 2005 Motobit Software, help{at}pstruh.cz, help v. 2.16.14