Javascript dropzone.js计数时($U文件[";文件]])始终得到5

Javascript dropzone.js计数时($U文件[";文件]])始终得到5,javascript,php,dropzone.js,Javascript,Php,Dropzone.js,我只是使用这个dropzone.js,发现这是一个bug,还是我做错了什么? 文档中没有任何演示 我已经搜索过了,没有发现任何与此相关的问题 我的html代码: <button id="submit-all" class="btn btn-primary">Submit all files</button> // for upload all <form action="upload.php" class="dropzone" id="my-dropzone">

我只是使用这个dropzone.js,发现这是一个bug,还是我做错了什么? 文档中没有任何演示

我已经搜索过了,没有发现任何与此相关的问题

我的html代码:

<button id="submit-all" class="btn btn-primary">Submit all files</button> // for upload all
<form action="upload.php" class="dropzone" id="my-dropzone">
  <label>Username:<input type="text" name="uname"/> </label> // only for test
  <label>Password:<input type="text" name="pass"/> </label> // only for test
  <div id="dropzonePreview"></div> 
</form>
提交所有文件//以便全部上载
用户名://仅用于测试
密码://仅用于测试
对于js:

Dropzone.options.myDropzone = {

// Prevents Dropzone from uploading dropped files immediately
autoProcessQueue: false,
parallelUploads:100,

init: function() {
var submitButton = document.querySelector("#submit-all")
myDropzone = this; // closure

submitButton.addEventListener("click", function() {
myDropzone.processQueue(); // Tell Dropzone to process all queued files.
});

// You might want to show the submit button only when 
// files are dropped here:
this.on("addedfile", function(file) {

// Create the remove button
var removeButton = Dropzone.createElement("<button class='removebutton'>Remove file</button>");


// Capture the Dropzone instance as closure.
var _this = this;

// Listen to the click event
removeButton.addEventListener("click", function(e) {
// Make sure the button click doesn't submit the form:
e.preventDefault();
e.stopPropagation();

// Remove the file preview.
_this.removeFile(file);
// If you want to the delete the file on the server as well,
// you can do the AJAX request here.
});

// Add the button to the file preview element.
file.previewElement.appendChild(removeButton);
});

this.on("success", function(file, responseText) {
// Handle the responseText here. For example, add the text to the preview element:
$(".removebutton").hide();
});


}
};
Dropzone.options.myDropzone={
//防止Dropzone立即上载删除的文件
自动处理队列:false,
并行上传:100,
init:function(){
var submitButton=document.querySelector(“全部提交”)
myDropzone=this;//闭包
addEventListener(“单击”,函数(){
myDropzone.processQueue();//告诉Dropzone处理所有排队的文件。
});
//您可能只想在以下情况下显示“提交”按钮:
//文件将放在此处:
this.on(“addedfile”,函数(文件){
//创建删除按钮
var removeButton=Dropzone.createElement(“删除文件”);
//将Dropzone实例捕获为闭包。
var_this=这个;
//收听单击事件
removeButton.addEventListener(“单击”),函数(e){
//确保单击按钮不会提交表单:
e、 预防默认值();
e、 停止传播();
//删除文件预览。
_此.removeFile(文件);
//如果还要删除服务器上的文件,
//您可以在这里执行AJAX请求。
});
//将按钮添加到文件预览元素。
file.previewElement.appendChild(removeButton);
});
this.on(“success”,函数(文件,responseText){
//在此处处理responseText。例如,将文本添加到预览元素:
$(“.removebutton”).hide();
});
}
};
my upload.php:

session_start();
$_SESSION["count"] = count($_FILES["file"]); // this always print 5
for ($i=0; $i < count($_FILES["file"]) ; $i++) { 

$target_dir = "gambar/";
$target_file = $target_dir . basename($_FILES["file"]["name"]);
// uplaod image
move_uploaded_file($_FILES["file"]["tmp_name"], $target_file);
$uname=$_POST['uname'];
$_SESSION["uname"] = $uname;
$pass=$_POST['pass'];
$_SESSION["pass"] = $pass;
}
session_start();
$_SESSION[“count”]=count($_FILES[“file”]);//这总是打印5
对于($i=0;$i
当我打印会话进行计数时,即使我上传了7个文件或2个文件,它也总是给我5个


有什么原因吗?

因为通过执行
计数($\u文件[“第一个\u文件\u输入\u名称])
您不是在计算上载的文件数,而是在计算文件本身的属性数

查看PHP文档,$_FILES数组采用关联数组的形式,每个文件项本身就是一个由5个标准成员组成的关联数组:

Array => (
          [file1] => Array (
                            [name] => SomeFile.jpg
                            [type] => image/jpeg
                            [tmp_name] => /tmp/php/tmp_name
                            [error] => UPLOAD_ERR_OK
                            [size] => 12345
                           )
          [file2] => Array (
                            [name] => SomeOtherFile.jpg
                            [type] => image/jpeg
                            [tmp_name] => /tmp/php/other_tmp_name
                            [error] => UPLOAD_ERR_OK
                            [size] => 123456
                           )
         )
您需要对文件数组进行计数。
count($\u个文件)

编辑

看起来您已经将drozonejs配置为使用并行单个请求处理排队的文件,每个文件上载一个请求,因此此计数现在将为1,但执行n次文件。有一个选项允许在一个上载请求中包含多个文件,而不是
uploadMultiple:true

我尝试了这一点,但它给我1,我上传了7个文件它唯一的计数1使用此计数($\u文件)需要一些额外的配置,用于在单个请求中的多个文件,请参阅editOK谢谢帮助,我缺少的是上传的多个:true