Answers for "upload progress bar script"

0

upload progress bar script

postFile('thumbnail' , 'progress-bar-thumbnail');


//  "InputFile" & "ProgressBar" are ID of elements 
function postFile(InputFile , ProgressBar) {
            var formdata = new FormData();

            formdata.append(InputFile, $('#'+InputFile)[0].files[0]);

            let request = new XMLHttpRequest();

            request.upload.addEventListener('progress', function (e) {
                let file1Size = $('#'+InputFile)[0].files[0].size;

                if (e.loaded <= file1Size) {
                    let percent = Math.round(e.loaded / file1Size * 100);
                    $('#'+ProgressBar).width(percent + '%').html(percent + '%');
                }

                if(e.loaded == e.total){
                    $('#'+ProgressBar).width(100 + '%').html(100 + '%');
                }
            });

  			// instead of '/admin/blog', write your form action
            request.open('post', '/admin/blog');
            request.timeout = 45000;
            request.send(formdata);
        }
Posted by: Guest on November-12-2020
0

file upload with progress bar

<center><form id="upload_container" action="upload.php" method="post"><div><label>Upload Image File:</label><input name="userImage" id="userImage" type="file" class="demoInputBox" /></div><br /><div><input type="submit" id="btnSubmit" value="Submit" class="btnSubmit" /></div><div id="progress-div"><div id="progress-bar"></div></div><div id="targetLayer"></div></form><div id="loader-icon" style="display:none;"><img src="loading.gif" /></div></center>
Posted by: Guest on May-06-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language