javascript - Get number of remaining files in plupload queue -
right have in plupload js:
$("#uploader").pluploadqueue({ // general settings runtimes: 'html5,silverlight,flash', url: baseurl + 'admin/pages_images/uploadtoserver/' + pageid, browse_button : 'uploadfiles', max_file_size: '300mb', chunk_size: '1mb', unique_names: true, // resize images on clientside if can // resize: {width: 320, height: 240, quality: 100}, // specify files browse filters: [ {title: "image files", extensions: "jpg,gif,png"}, {title: "zip files", extensions: "zip"} ], // flash/silverlight paths flash_swf_url: baseurl + 'assets/js/plupload/plupload.flash.swf', silverlight_xap_url: baseurl + 'assets/js/plupload/plupload.silverlight.xap', // preinit events, bound before internal events preinit: { init: function(up, info) { log('[init]', 'info:', info, 'features:', up.features); }, uploadfile: function(up, file) { log('[uploadfile]', file); // can override settings before file uploaded // up.settings.url = 'upload.php?id=' + file.id; // up.settings.multipart_params = {param1: 'value1', param2: 'value2'}; } }, // post init events, bound after internal events init: { refresh: function(up) { // called when upload shim moved log('[refresh]'); }, statechanged: function(up) { // called when state of queue changed log('[statechanged]', up.state == plupload.started ? "started": "stopped"); }, queuechanged: function(up) { // called when files in queue changed adding/removing files log('[queuechanged]'); }, uploadprogress: function(up, file) { // called while file being uploaded log('[uploadprogress]', 'file:', file, "total:", up.total); }, filesadded: function(up, files) { // callced when files added queue log('[filesadded]'); plupload.each(files, function(file) { log(' file:', file); }); }, filesremoved: function(up, files) { // called when files removed queue log('[filesremoved]'); plupload.each(files, function(file) { log(' file:', file); }); }, fileuploaded: function(up, file, info) { // called when file has finished uploading log('[fileuploaded] file:', file, "info:", info); var myuploader = $("#uploader").pluploadqueue(); myuploader.bind('queuechanged', function(up, files){ remaining_files = myuploader.files.length; alert('all files uploaded!'); }); $.ajax({ type : "post", url : baseurl + 'admin/pages/reload/' + pageid, success: function(data){ if(data) { alert('file uploaded!'); } else { alert('ajax error'); } } }); }, chunkuploaded: function(up, file, info) { // called when file chunk has finished uploading log('[chunkuploaded] file:', file, "info:", info); }, error: function(up, args) { // called when error has occured // handle file specific error , general error if (args.file) { log('[error]', args, "file:", args.file); } else { log('[error]', args); } } } }); $('#log').val(''); $('#clear').click(function(e) { e.preventdefault(); $("#uploader").pluploadqueue().splice(); });
but of course, it's not working. because don't know how decrement remaining files, or precise how number of files in queu in first place, can -1 them , ompare initial value. how that?
you have bind event , create counter
a full answer here
var files_remaining = 0; $("#uploader").pluploadqueue({ // general settings runtimes: 'html5,silverlight,flash', url: baseurl + 'admin/pages_images/uploadtoserver/' + pageid, browse_button : 'uploadfiles', max_file_size: '300mb', chunk_size: '1mb', unique_names: true, // resize images on clientside if can // resize: {width: 320, height: 240, quality: 100}, // specify files browse filters: [ {title: "image files", extensions: "jpg,gif,png"}, {title: "zip files", extensions: "zip"} ], // flash/silverlight paths flash_swf_url: baseurl + 'assets/js/plupload/plupload.flash.swf', silverlight_xap_url: baseurl + 'assets/js/plupload/plupload.silverlight.xap', // preinit events, bound before internal events preinit: { init: function(up, info) { log('[init]', 'info:', info, 'features:', up.features); }, uploadfile: function(up, file) { log('[uploadfile]', file); // can override settings before file uploaded // up.settings.url = 'upload.php?id=' + file.id; // up.settings.multipart_params = {param1: 'value1', param2: 'value2'}; } }, // post init events, bound after internal events init: { refresh: function(up) { // called when upload shim moved log('[refresh]'); }, statechanged: function(up) { // called when state of queue changed log('[statechanged]', up.state == plupload.started ? "started": "stopped"); }, queuechanged: function(up) { // called when files in queue changed adding/removing files log('[queuechanged]'); }, uploadprogress: function(up, file) { // called while file being uploaded log('[uploadprogress]', 'file:', file, "total:", up.total); }, filesadded: function(up, files) { // callced when files added queue log('[filesadded]'); plupload.each(files, function(file) { log(' file:', file); }); }, filesremoved: function(up, files) { // called when files removed queue log('[filesremoved]'); plupload.each(files, function(file) { log(' file:', file); }); }, fileuploaded: function(up, file, info) { // called when file has finished uploading log('[fileuploaded] file:', file, "info:", info); var myuploader = $("#uploader").pluploadqueue(); myuploader.bind('queuechanged', function(up, files){ remaining_files = myuploader.files.length; alert('all files uploaded!'); }); $.ajax({ type : "post", url : baseurl + 'admin/pages/reload/' + pageid, success: function(data){ if(data) { alert('file uploaded!'); } else { alert('ajax error'); } } }); }, chunkuploaded: function(up, file, info) { // called when file chunk has finished uploading log('[chunkuploaded] file:', file, "info:", info); }, error: function(up, args) { // called when error has occured // handle file specific error , general error if (args.file) { log('[error]', args, "file:", args.file); } else { log('[error]', args); } } } }); var uploader = $("#uploader").pluploadqueue(); uploader.bind('queuechanged', function(up, files) { files_remaining = uploader.files.length; }); uploader.bind('fileuploaded', function(up, file, res) { files_remaining--; if (files_remaining == 0) { alert('complete!'); } });
Comments
Post a Comment