javascript - upload photos at a time -


i'm trying upload more photo @ same object xmlhttprequest.

 if(files.length <= 6) {         for(var = 0; < files.length; i++)   {        var formdata = new formdata();       formdata.append('action', 'uploadphoto');       formdata.append('photo_id', id);       formdata.append('file'+id, files[i]);       uploadfile(formdata, id);   }       }   function uploadfile(formdata, id)  {      var xhr = new xmlhttprequest();  xhr.open('post', 'uploadphoto.php', false);     xhr.onload = function (){};     xhr.send(formdata); } 

the problem photo upload repeat same. think happens because loop continue , photo no finish of upload.

as comments, id random number, im geussing needs random on each iteration. have set outside of loop however, going overwritten on each loop, hence ever seeing 1 file uploaded. depending on random funciton using, there possiblity generate same number again, , have files become randomly overwritten in same fashion doing here.

here have employed timestamp technique instead, unique @ time it. try :

if(files.length <= 6) {     for(var = 0; < files.length; i++)   {    var id =date().gettime();   var formdata = new formdata();   formdata.append('action', 'uploadphoto');   formdata.append('photo_id', id);   formdata.append('file'+id, files[i]);   uploadfile(formdata, id);   }   }  function uploadfile(formdata, id)  {      var xhr = new xmlhttprequest();  xhr.open('post', 'uploadphoto.php', false);     xhr.onload = function (){};     xhr.send(formdata); } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -