Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Have you tried <code>xhr.upload.onprogress</code> instead of <code>xhr.onprogress</code>?</p> <p>If that doesn't work too, you could establish another JavaScript AJAX call, like you said. Recently, I've made an upload system that read the file line per line, and it needed to show some extra information about the upload, and not just the percentage, so I did something like this:</p> <ul> <li>The main page makes an AJAX request to a file responsible to process the file</li> <li>In that file, I had to close the connection, so the AJAX request could complete, but the PHP script would still be running, using this:</li> </ul> <pre class="lang-php prettyprint-override"><code>ob_start(); $file = tempnam('/tmp', uniqid()); // create a temp file to show status of the action echo json_encode(array('file' =&gt; $file)); header('Content-length: '.ob_get_length()); header('Connection: close'); ob_end_flush(); flush(); // The AJAX request is completed here, but the script is still running... function writeToFile($handle, $arr) { ftruncate($handle, 0); // empty file fwrite($handle, json_encode($arr)); } $handle = fopen($file, 'w'); while (readLine($uploadedFile)) { // code to process line writeToFile($handle, array('progress' =&gt; $current / $total, 'action' =&gt; 'Reading...')); } // insert into database writeToFile($handle, array('progress' =&gt; '100', 'action' =&gt; 'Inserting into database...')); fclose($handle); </code></pre> <ul> <li>At the main page, the AJAX request would return the name of the file that contains the information, so I would create several GET requests to that file, using <code>setInterval</code> method</li> </ul> <p><em><strong>Note:</strong> in my case, I created another PHP file to show the contents of the progress file (with <code>file_get_contents</code>), so I could manually delete that file when the operation completes</em></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload