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...

BlackPanther
  • 1,732
  • 1
  • 14
  • 19
  • 1
    progress of what ? percent of upload ? you cannot show percent but you can show a please wait or sth – OnlyMAJ Dec 21 '14 at 08: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 http://stackoverflow.com/questions/374644/how-do-i-capture-response-of-form-submit/374686#374686 – chank Dec 21 '14 at 08: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? – BlackPanther Dec 21 '14 at 08: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. – Sergiu Paraschiv Dec 21 '14 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. – Jelle De Loecker Jul 01 '15 at 14:12
  • @skerit At last... someone sensible. I've almost stopped asking questions on Stackoverflow. SO is filled with people who are just onto down-voting a question on the first glance and saying questions are not sensible, etc.. and doesn't even bother to post a comment... Its not like SO is running out of space! – BlackPanther Jul 01 '15 at 16:31
  • I agree with @skerit and BlackPanther and just voted to reopen this question. – Tiago Martins Peres Jun 10 '20 at 10:55

1 Answers1

-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

Pawel Uchida-Psztyc
  • 3,735
  • 2
  • 20
  • 41
  • Those are specifically for AJAX (or at least what people mean when they say AJAX), which OP doesn't want. – Shai Dec 21 '14 at 10:36
  • 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. – Pawel Uchida-Psztyc Dec 21 '14 at 11:39