我在下面添加了dropzone代码
<html>
<head>
<!-- 1 -->
<link href="dropzone.css" type="text/css" rel="stylesheet" />
<!-- 2 -->
<script src="dropzone.js"></script>>
</head>
<body>
<!-- 3 -->
<form action="upload.php" class="dropzone"></form>
</body>
</html>
它工作正常。 但我想知道如何添加删除按钮以从服务器删除特定文件。
答案 0 :(得分:1)
首先,您必须向选项addRemoveLinks: true
然后我们会监听事件,当一个文件被删除时,做一个Ajax调用从服务器上删除它(在这里我只是发送文件名),然后在那里只做代码隐藏删除文件。
Dropzone.autoDiscover = false;
myDropzone = new Dropzone("#DzUpload", {
url: 'upload.php',
addRemoveLinks: true, //This will show remove button
});
//Init Dropzone
myDropzone.on("removedfile", function (file) {
if (!file.name) { return; } // The file hasn't been uploaded
$.ajax({
type: 'POST',
url: 'delete.php',
dataType: "json",
data: { FileName: file.name },
success: function (result) {
console.log("deleted")
}
});
});