S
S
systemiv2013-01-16 14:02:26
PHP
systemiv, 2013-01-16 14:02:26

Ajax file upload?

The page displays a select, with a list. Next to it is a file selection button (implemented using the jQuery File Upload lag).
I select a file, there is a process. Then I need to select another select and another file without waiting and send it for processing in the same way.
How to implement it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
neosys, 2013-01-16
@systemiv

Implement something like a stack (array) where you will put new files.
In parallel, organize a function that listens to some custom event like "file-upload-added".
In the function, implement a mechanism for selecting files from the stack and send files for download one by one in the background.
I mean something like this:

var files = [];

.bind("file-upload-added", function() {
    var file;
    
    if (files.length) {
        file = files.pop();
    } else {
        return;
    }    
    
    $.ajax({
        ...
        ...
        ...
        
        success: function() {
            .trigger('file-upload-added');
        }
    })
});

.bind("file-upload-selected", function(file) {
    files.push(file);
    
    .trigger('file-upload-added');
})

Then tweak to suit your needs.

F
friday, 2013-01-16
@friday

For example, like this:
<iframe name="upload-iframe" style="display: none;"></iframe> <form id="upload-form" action="/upload" target="upload-iframe" method="post" enctype="multipart/form-data"> <input type="file" name="file" id="file-input"/> <script> $('#file-input').change(function(){ $('#upload-form').submit(); }); </script>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question