我想使用dropzone.js向服务器发送多个图像,只有当"提交"按下按钮。我已经尝试了,但无法找到解决方案。 这是我的dropzone代码:
Dropzone.options.images = { // The camelized version of the ID of the form element
// The configuration we've talked about above
paramName: "file",
autoProcessQueue: false,
uploadMultiple: true,
parallelUploads: 25,
maxFiles: 25,
// The setting up of the dropzone
init: function () {
var myDropzone = this;
$("#submit").click(function (e) {
myDropzone.processQueue();
alert("it worked");
//e.preventDefault();
//e.stopPropagation();
});
this.on("addedfile", function (file) {
// Create the remove button
var removeButton = Dropzone.createElement("<button>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);
});
}
};
这是我的php代码,用于获取和存储目录中的文件:
<?php
$ds= DIRECTORY_SEPARATOR;
$storeFolder = 'uploads';
if (!empty($_FILES)) {
echo "file in not empty";
$tempFile = $_FILES['file']['tmp_name']; //3
$targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds; //4
$targetFile = $targetPath. $_FILES['file']['name']; //5
move_uploaded_file($tempFile,$targetFile); //6
}
?>