【发布时间】:2017-11-08 10:26:32
【问题描述】:
我只是使用这个 dropzone.js 并发现这是一个错误或者我做错了什么? 文档没有任何演示。
我已经搜索过这个并且没有看到任何关于这个的问题/问题
我的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();
});
}
};
我的上传.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;
}
当我打印会话进行计数时,即使我上传 7 个文件或 2 个文件,它也总是给我 5 个。
有什么理由吗?
【问题讨论】:
标签: javascript php dropzone.js