Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Determine the percentage of the file uploaded to the server using php

$(function() {

    var bar = $('.bar');
    var percent = $('.percent');
    var status = $('#status');

    $('form').ajaxForm({
        beforeSend: function() {
            status.empty();
            var percentVal = '0%';
            bar.width(percentVal);
            percent.html(percentVal);
        },
        uploadProgress: function(event, position, total, percentComplete) {
            var percentVal = percentComplete + '%';
            bar.width(percentVal);
            percent.html(percentVal);
        },
        complete: function(xhr) {
            status.html(xhr.responseText);
        }
    });
}); 





<form action="file-echo2.php" method="post" enctype="multipart/form-data">
    <input type="file" name="myfile"><br>
    <input type="submit" value="Upload File to Server">
</form>

<div class="progress">
    <div class="bar"></div >
    <div class="percent">0%</div >
</div>

<div id="status"></div>
Comment

Determine the percentage of the file uploaded to the server using php

$.ajax({
  xhr: function() {
    var xhr = new window.XMLHttpRequest();

    xhr.upload.addEventListener("progress", function(evt) {
      if (evt.lengthComputable) {
        var percentComplete = evt.loaded / evt.total;
        percentComplete = parseInt(percentComplete * 100);
        console.log(percentComplete);

        if (percentComplete === 100) {

        }

      }
    }, false);

    return xhr;
  },
  url: posturlfile,
  type: "POST",
  data: JSON.stringify(fileuploaddata),
  contentType: "application/json",
  dataType: "json",
  success: function(result) {
    console.log(result);
  }
});
Comment

PREVIOUS NEXT
Code Example
Php :: Add Spatie provider to providers 
Php :: Debloat Wordpress 
Php :: tina4 add debugging 
Php :: laravel-filemanager showing blank page 
Php :: merge three array in php 
Php :: what is livewire 
Php :: php validation form 
Php :: how to get last 10 digit from number in php 
Php :: how to check request method in php 
Php :: multipart json test laravel 
Php :: php print array key and value 
Php :: Laravel Http client retry request if fail 
Php :: How to on auto_recording using zoom api in php 
Php :: Get and access to the order data properties (in an array of values): 
Php :: Remove WordPress Login error hints 
Php :: laravel collect whereNotIn not working 
Php :: check input value is not empty or spaced php 
Php :: php variable array for json encode data 
Php :: php delete acc 
Php :: Laravel You may use the sectionMissing directive to determine if a section does not have content: 
Php :: Add class to menu anchors 
Php :: null php 
Php :: session 
Php :: how to implement email verification in laravel 
Php :: run php with xampp 
Php :: php in browser 
Php :: authenticate user with phone laravel 
Php :: laravel edit 
Java :: java create jframe 
Java :: spigot custom join message 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =