I want to develop a tree of folders and files with a drag-and-drop upload on folders.
Example:
For the drag-and-drop upload, I fund jQuery File Upload.
The basic code is:
$('#fileupload').fileupload({
dataType: 'json',
url: 'php/index.php',
dropZone: $(document),
done: function (e, data) {
$.each(data.result, function (index, file) {
$('<p/>').text(file.name).appendTo(document.body);
});
}
});
In my project, I've multi dropzone (my folders) like for example :
<ul>
<li>Bookmarks</li>
<li>Search</li>
<li>Web dev</li>
...
</ul>
How to change the code above to handle the multi dropzone with id, class and jQuery selectors?
I tried something like this but obviously it doesn't work:
<ul>
<li id="folder1" class="folder">Bookmarks</li>
<li id="folder2" class="folder">Search</li>
<li id="folder3" class="folder">Web dev</li>
...
</ul>
.
$('.folder').fileupload({
dataType: 'json',
url: 'php/index.php',
dropZone: $('.folder'),
done: function (e, data) {
$.each(data.result, function (index, file) {
$('<p/>').text($(this).attr(id)).appendTo(document.body);
});
}
});
Issues:
I found a solution with a colleague.
Actually it wasn't complicated:
$('.folder').each(function(){
var $this = $(this);
$this.fileupload({
dataType: 'json',
url: 'php/index.php',
dropZone: $this,
done: function (e, data) {
$.each(data.result, function (index, file) {
$('<p/>').text($this.attr('id')).appendTo(document.body);
});
}
});
});
Edit: My bad, this answer was in the documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With