I make a simple form for uploading files. With form I can add multiple files to a queue. With special button I can remove file from a queue. But for some reason it doesn't work in a way I want. By clicking "Unload files" just 2 files are uploading to server. If I click second time than second 2 files are uploading. All code are below. How to upload ALL files by click a button just ones? Thanks in advance.
HTML:
<div class="panel panel-default">
<div class="panel-heading">
<strong>Прикрепить файлы</strong>
</div>
<div class="panel-body">
<button type="button" class="btn btn-primary" id="add-file">
<span class="glyphicon glyphicon-folder-close" aria-hidden="true"></span> Обзор...
</button>
<button type="button" class="btn btn-primary" id="upload-file">
<span class="glyphicon glyphicon-folder-close" aria-hidden="true"></span> Загрузить
</button>
<ul class="list-group dropzone-previews" style="margin-top: 10px; margin-bottom: 0;"></ul>
</div>
</div>
JS:
$(".panel").dropzone({
url: "upload.php",
autoProcessQueue: false,
init: function() {
var myDropzone = this;
$('#upload-file').click(function() {
myDropzone.processQueue();
});
},
clickable: '#add-file',
acceptedFiles: 'image/*,application/pdf,application/msword',
previewsContainer: '.dropzone-previews',
previewTemplate: '<li class="working list-group-item">' +
'<span data-dz-name></span> <span data-dz-size></span> (<u data-dz-remove>Удалить</u>)' +
'<div class="progress" style="margin-top: 10px; margin-bottom: 0;">' +
'<div class="progress-bar" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" data-dz-uploadprogress></div>' +
'</div></li>'
});
And my server script on PHP:
<?php
$ds = DIRECTORY_SEPARATOR;
$storeFolder = 'uploads';
if (!empty($_FILES)) {
$tempFile = $_FILES['file']['tmp_name'];
$targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;
$targetFile = $targetPath. $_FILES['file']['name'];
move_uploaded_file($tempFile,$targetFile);
}
?>
Just increase the value of parallelUploads to 10 or 20. By default it will send two file at a time to server, So you need to increase the value of parallelUploads and it will work.
$(".panel").dropzone({
url: "upload.php",
autoProcessQueue: false,
init: function () {
var myDropzone = this;
},
parallelUploads: 20,
clickable: '#add-file',
acceptedFiles: 'image/*,application/pdf,application/msword',
previewsContainer: '.dropzone-previews',
previewTemplate: '<li class="working list-group-item">' +
'<span data-dz-name></span> <span data-dz-size></span> (<u data-dz-remove>Удалить</u>)' +
'<div class="progress" style="margin-top: 10px; margin-bottom: 0;">' +
'<div class="progress-bar" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" data-dz-uploadprogress></div>' +
'</div></li>'
});
$('#upload-file').click(function () {
myDropzone.processQueue();
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.