5

Is it possible to show a progressbar in a normal file upload, without ajax? For example I have a form :

<form action='fileupload.php' method='POST'> <input type='file' name='file1' /> <input type='submit' value='Upload'> </form> 

And I select a file and click upload. Is it possible to display a progressbar, until the file is completely uploaded and redirects the page? Because non-AJAX upload is good for my situation and I don't want to use an entire complex plugin just for a progressbar.

EDIT :

I understand this question has not had a conclusive answer so far, but it is definitely not a duplicate of the question marked. Explanation for those who can't understand: The progress of a file upload should be known at two places- The Server, while receiving the file packets. The Client Browser, while receiving the acknowledgement from the server for respective packets (Internet Protocols?). Currently almost all the algorithms for progress-bars are based on explicitly sending AJAX data parallel to the file upload between javascript on client and PHP on server. My question is if there is any way to know the progress of file upload without the parallel communication, since the browser must already know the packets received in at the server...

7
  • 1
    progress of what ? percent of upload ? you cannot show percent but you can show a please wait or sth Commented Dec 21, 2014 at 8:27
  • 1
    you could try to start progressbar onsubmit and stop on response from submit. In the following link it was suggested to get response without ajax stackoverflow.com/questions/374644/… Commented Dec 21, 2014 at 8:27
  • I undersand that I can show a moving sign to say its being uploaded. But progress is important, since the files could be large. Is there a way in php to get the size of a file currently being uploaded, in real time and to read and display that using ajax, rather than uploading the entire file using ajax? Commented Dec 21, 2014 at 8:38
  • Also, the reason the existing solutions are "complex" is that the problem solved is complex. You need to make sure it's working on as many browsers as possible. Older browsers require different mechanisms (iFrame, Flash, FileAPI, etc.) for this to work. There are solutions that require special server-side code/setup (APC). And all of them have to be hidden behind a common API. Commented Dec 21, 2014 at 11:03
  • 4
    This isn't a duplicate since the question specifically asks for a solution "without ajax". You might not like the implementation but the question is valid. Commented Jul 1, 2015 at 14:12

1 Answer 1

-1

You can monitor progress of sending the file(s) using progress events. See examples on https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Monitoring_progress

Sign up to request clarification or add additional context in comments.

2 Comments

Those are specifically for AJAX (or at least what people mean when they say AJAX), which OP doesn't want.
Alternatively you can use iframe and target attribute of form element. If you reload the page submitting the form you can't trace progress events. But if you send the form via iframe you can add event listeners (like "load") to it and track when the form was submitted.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.