简体   繁体   English

如何使用按钮上传Dropzone.js的2个以上文件

[英]How to upload more than 2 files by Dropzone.js with button

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. 通过单击“卸载文件”,只有2个文件正在上载到服务器。 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: 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: 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上的服务器脚本:

<?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. 只需将parallelUploads的值增加到10或20即可。默认情况下,它将一次向服务器发送两个文件,因此您需要增加parallelUploads的值才能工作。

 $(".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();
        });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM