javascript - How do I numerically rename files in Plupload before they're uploaded? -


i using plupload jquery ui widget basis uploader. widget allows user drag reorder added files.

upload begun automatically upon submission of form, not manually user. during upload, ui blocked user can't add anymore files.

before upload begins, need rename of files upload numerically first file uploaded (the 1 @ top of jquery ui widget list) '1', second '2' , on.

for instance, given following list:

bob.jpg ann.jpg doug.jpg chris.jpg 

i want have them renamed:

1.jpg 2.jpg 3.jpg 4.jpg 

this works when user adds new files or removes existing files. doesn't work when user drag reorders files. here instantiation code uploader:

$('#' + div_id).plupload({   runtimes: 'html5, flash, silverlight',   url: 'upload',   unique_names: false,   rename: true,   sortable: true,   buttons: { browse: true, start: false, stop: false },          // flash settings   flash_swf_url: 'js/plupload/plupload.flash.swf',    // silverlight settings   silverlight_xap_url : 'js/plupload/plupload.silverlight.xap',   init: {    queuechanged: function(up) {      (var = 0; < up.files.length; i++) {        up.files[i].name = (i+1);      }    }  } }); 

i can't figure out how detect when user drag reorders. failing that, don't see event fires when upload of queue first begins.

in case else comes across problem:

instead of using queuechanged() event used jquery every plupload instance , within jquery's .each() loop used code:

var regex = /(?:\.([^.]+))?$/; (var = 0; < uploader.files.length; i++) {   var ext = regex.exec(uploader.files[i].name)[1];   uploader.files[i].name = (ext == undefined) ? (i+1) : (i+1) + '.' + ext; } uploader.start(); 

this way don't renaming until before uploading. has added advantage of not renaming files in ui widget before upload (this avoiding confusion end user).


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -