Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Progress bar for upload

Status
Not open for further replies.

erhancom

Programmer
Feb 19, 2007
4
TR
My upload code:

<form enctype="multipart/form-data" action="?newup=1" method="post" id=form1 name=form1>
<input type=file name=file>
<input type=submit value=submit name=submit>
</form>
<%
If Request.QueryString("newup") = 1 Then
asdfg = Request.BinaryRead(Request.TotalBytes)
LenBinary = LenB(asdfg)
If LenBinary > 0 Then
Set RST = CreateObject("ADODB.Recordset")
RST.Fields.Append "myBinary", 201, LenBinary
RST.Open
RST.AddNew
RST("myBinary").AppendChunk asdfg
RST.Update
strData = RST("myBinary")
RST.Close
Set RST = Nothing
End If
'FileName
fnbgn = instr(1, strData, "file") + 17
fnend = instr(fnbgn, strData, chr(34))
FileName = Mid(strData,fnbgn,(fnend - fnbgn))
'BinaryData
dbbgn = instr(1, strData, "file")
dbbgn = instr(dbbgn, strData, chr(10)) + 1
dbbgn = instr(dbbgn, strData, chr(10)) + 1
dbbgn = instr(dbbgn, strData, chr(10)) + 1
dbend = instr(dbbgn, strData, "-----") - 2
BinaryData = Mid(strData,dbbgn,(dbend - dbbgn))
FileSize = Len(BinaryData)

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso_OpenTextFile(Server.MapPath("\")&"\"&fso.GetFi leName(FileName), 2, True)
f.Write BinaryData
Set f = Nothing
Set fso = Nothing
End If

Response.Write "Upload Ok."
%>

I Need a progress bar for this code.

Thanks.
 
I don't think ASP gets access to the file until the Request from the browser is complete.

Perhaps you could use an animated GIF of an hourglass?
 
He can do it with a Response.Flush method. Every few lines insert a Response.Flush and a function call to a progress bar. The problem comes in it most likely won't be an accurate bar.

[small]"There's an old saying in Tennessee — I know it's in Texas, probably in Tennessee — that says, fool me once, shame on — shame on you. Fool me — you can't get fooled again." - George W. Bush[/small]
<.
 
How can i use Response.Flush method.
Do you have any example.
 
Response.Flush sends anything that has been written to the response buffer (Response.Write) so far to the browser.

So if you were to write something like:
Code:
Response.Write "something"
Response.Flush

'lots of code

Response.Write "done"
You would see the "something" almost immediately since it is flushed to the browser, then after the "lots of code" section finally finished runnig you would see the "done" statement.

Sometime about 3 years ago I wrote a loading message FAQ here: faq333-3223

Basically it turns the buffer off completely so it can display a loading message. Once the page is loaded the loading message is hidden using client-side CSS so the rest of the page can be displayed.
You could use this same logic to load an animated gif for a loading bar. In this instance I don't think you could use a real loading bar because as Sheco said I don't think you get access to the file until it has completely loaded, so you won't know what size the file is.
Additionally, I'm not sure you will even be able to display the waiting message until after the file has been uploaded. I think Your ASP script won't start to execute until the file has been completely posted to your web server. One solution would be to use whatever button click occurs on the previous page to display a loading message or animated gif which would then automatically go away when the upload stops and the client starts to see the next page.

-T

 
You can't have a real progress bar because the server does not know the size of the incoming file.

You can however display an animation that alerts the user that something is happening so they will not think that the page has stopped responding.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top