Sto provando a modificare il codice di questa pagina http://www.devpro.it/FileReference/
nella pagina si effettua un test che uploada un solo file, io devo far uploadare tutti i file che si selezionano.
Ho modificato il codice con la variabile totalindex che fa da contatore per il file che si sta uploadando, e ho messo un controllo nell'on Complete, per verificare se il file è l'ultimo della lista. Sembra funzionare ma dopo il primo file, richiama l'on select e poi si blocca...


Codice PHP:
// these variables are just for this example
var actionElement;
var 
progressElement;
var 
totalIndex 0;   // creo la variabile contatore 

// html element initializzation
function elementsInit() {
    if(
document.getElementById) {
        
actionElement document.getElementById('action');
        
progressElement document.getElementById('progress');
    }
    else {
        
actionElement document.all.action;
        
progressElement document.all.progress;
    }
}

// function to write what's up
function trace(what) {
    if(
actionElement.innerHTML != what)
        
actionElement.innerHTML what;
}

// function to emulate a progress bar
function bar(p) {
    var 
newWidth Math.floor(300 100) + 'px';
    if(
progressElement.style.width != newWidth)
        
progressElement.style.width newWidth;
}

// listener as FileReferenceList Object listener
var listener = new Object();
        
// invoked on cancel when upload dialog is open
listener.onCancel = function(file) {
    
actionElement.innerHTML 'onCancel';
}

// invoked when a user chose a file
listener.onSelect = function(file) {
        
alert("Chiamo OnSelect "+totalIndex);
           
if ( 
totalIndex == ) var file.fileList.length;
alert("ok1");
    if(
file.fileList.length 0) { 
        
// listener as FileReference Object listener ... same methods
        // same returned parameters, isn't cool ? :-)
        
var FileListener = new Object(); 
        
        
// where is you uploaad server side script ?
        
FileListener.serverfile 'FileReference.php'
        
        
// usefull one4allErrors function, created by myself
        
FileListener.onError = function(fileerrorString) {
            
trace("Error with: " file.name "
Type: " 
errorString);
        }
        
// common error functions
        
FileListener.onHTTPError =
        
FileListener.onIOError =
        
FileListener.onSecurityError = function(fileerrorString) {
            if(
errorString == undefined)
                
errorString 'HTTP or Input Output Error';
            
this.onError(fileerrorString);
        }
        
        
// invoked on cancel when upload dialog is open
        
FileListener.onCancel = function(file) {
            
trace('onCancel');
        }
        
        
// invoked when file is starting to be uploaded / downloaded
        
FileListener.onOpen = function(file) {
            
progressElement.style.display 'block';
            
trace('onOpen: ' file.name);
        }
        
        
// ... while file is uploaded / downloaded
        
FileListener.onProgress = function(filebytesLoadedbytesTotal) {
            var 
= new Number(Math.floor(bytesLoaded bytesTotal 100));
            
trace('onProgress: ' '%');
            
bar(p);
        }
        
        
// invoked when file is uploaded / downloaded
            
FileListener.onComplete = function(file) { 
            
document.getElementById('progress').style.display 'none';
            
trace('onComplete: ' file.name); alert("completato file "+totalIndex+" di "+b);
//controllo se ci sono altri file, e nel caso riavvio il procedimento richiamando l'onselect
                        
if ( totalIndex ) { alert("prova"); listener.onSelect(file); }                                                              
         }        
        
        
// add listener to file
        
file.fileList[totalIndex].addListener(FileListener);
                             
        
// now onSelect is not defined because file was just selected from List
        // ... then just check size and try to upload
        
var maxSize 8004800;  
        if(
file.fileList[totalIndex].size maxSize)
            
trace('File is too big for a test');
                else if(!
file.fileList[totalIndex].upload(FileListener.serverfile)) 
            
trace('Upload dialog failed to open.'); 
            
totalIndex++;     

    }




// FileReferenceList class initializzation
var fileRef = new FileReferenceList();

// adding a listener
fileRef.addListener(listener);

// filetypes variable example
var filetype = [
    
    {
description "Images (*.jpg, *.jpeg, *.gif, *.png, *.bmp)",
    
extension "*.jpg; *.jpeg; *.gif; *.png; *.bmp;"}
];