Dropzone.js-如何从服务器删除文件? [英] Dropzone.js- How to delete files from server?

查看:879
本文介绍了Dropzone.js-如何从服务器删除文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用dropzone.js。
当我尝试删除文件时,只会删除缩略图,但不会删除服务器中的文件。
我尝试了一些方法,但它只是给了我客户端图像的名称而不是服务器端的名称(两个名称都不同,以加密形式存储名称)。

I am using dropzone.js. When I try to delete files only the thumbnails get deleted but not the files from server. I tried some ways but it just gives me the name of the image which was on client side and not the name on server side(both names are different, storing names in encrypted form).

任何帮助都会非常感激..

Any help would be much appreciated..

推荐答案

我处理这个问题的方法是文件上传并存储在服务器上,我回显我在服务器上提供文件的名称,并将其存储在JS对象中,如下所示:

The way I handle this, is after each file is uploaded and stored on the server, I echo back the name I give the file on my server, and store it in a JS object, something like this:

PHP :

move_uploaded_file($_FILES['file']['tmp_name'], $newFileName);
echo $newFileName;

JS:

dropZone.on("success", function(file, serverFileName) {
  fileList[serverFileName] = {"serverFileName" : serverFileName, "fileName" : file.name };
});

有了这个,你可以在PHP中编写一个删除脚本,它接受serverFileName并且实际删除,例如:

With this, you can then write a delete script in PHP that takes in the "serverFileName" and does the actual deletion, such as:

JS:

$.ajax({
    url: "upload/delete_temp_files.php",
    type: "POST",
    data: { "fileList" : JSON.stringify(fileList) }
});

PHP:

$fileList = json_decode($_POST['fileList']);

for($i = 0; $i < sizeof($fileList); $i++)
{
    unlink(basename($fileList[$i]));
}

这篇关于Dropzone.js-如何从服务器删除文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆