File uploads: Percentage completed progress bar

前端 未结 4 1950
被撕碎了的回忆
被撕碎了的回忆 2021-02-05 16:37

I\'m trying to add a \'percentage completed so far\' progress bar to avatar uploads in BuddyPress. The aim is to stop users navigating away from the page before the upload is co

4条回答
  •  臣服心动
    2021-02-05 17:12

    I'm not familiar with BuddyPress, but all upload handlers (including the HTML5 XHR one that androbin outlined) will have a file progress hook point that you can bind to.

    I've used uploadify, uploadifive and swfupload, and they can all interact with the same progress function handler in order to acheive the same progress bar result.

    // SWFUpload
    $elem.bind('uploadProgress', function(event, file, bytesLoaded) { fnProgress(file, bytesLoaded); })
    
    // Uploadify
    $elem.uploadify({ onUploadProgress: function (file, bytesUploaded, bytesTotal, totalBytesUploaded, totalBytesTotal) { fnProgress(file, bytesUploaded); });
    
    // Uploadfive
    $elem.uploadifive({ onProgress: function(file, e) { fn.onProgress(file, e.loaded); });
    

    Uploadifive, being an HTML5 based uploader, simply binds to the XHR 'progress' event, so all these properties will be available to any HTML5 uploader.

    As for the actual progress bar code..

    HTML:

提交回复
热议问题