Dropzone.js remove button with php(Dropzone.js 用 php 删除按钮)
问题描述
我使用 dropzone.js 来制作一个不错的上传表单.我链接了 php 代码来上传文件,并设置了 addRemoveLinks=true 所以我有删除按钮.
I use dropzone.js for a nice upload form. I linked the php code to upload the files and i setted addRemoveLinks=true so i have the remove button.
我需要一个想法,当我点击删除按钮时,如何有效地删除使用 php 代码上传的文件.
I need an idea how to efectivly delete the filse uploaded with a php code when i hit remove button.
php 做起来很简单,但我不需要知道如何关联它们.我已经尝试在此函数中使用 $.post 删除文件:函数(文件)但没有成功.
The php is simple to do but i need t know how to relate them. I already tryed using $.post in this function removedfile: function(file) but no succes.
removedfile: function(file) {
$.post("test.php");
var _ref;
return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0;
},
推荐答案
首先,你不应该简单地覆盖默认的 removedfile 事件处理程序,而应该注册你自己的处理程序.
First off, you shouldn't simply overwrite the default removedfile event handler, but rather register your own handler along with it.
您需要先从服务器取回 ID(这样您就知道如何关联它),然后使用它来设置删除调用.
You need to first get the ID back from the server (so you know how to relate to it) and then use this to setup the delete call.
Dropzone.options.myDropzone = {
init: function() {
this.on("success", function(file, response) {
file.serverId = response; // If you just return the ID when storing the file
// You can also return a JSON object then the line would
// look something like this:
//
// file.serverId = response.id;
//
// In that case make sure that you respond with the mime type
// application/json
});
this.on("removedfile", function(file) {
if (!file.serverId) { return; } // The file hasn't been uploaded
$.post("delete-file.php?id=" + file.serverId); // Send the file id along
});
}
这篇关于Dropzone.js 用 php 删除按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Dropzone.js 用 php 删除按钮
基础教程推荐
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何替换eregi() 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
