如何从Dropzone的投递箱区域中删除文件?

时间:2016-11-29 07:37:52

标签: javascript php jquery dropzone.js jquery-file-upload

我使用Dropzone.js上传应用程序中的文件。用户从本地计算机的文件管理器中选择图片到dropzone区域后,如果用户稍后发现他/她想要删除一个挑选的图片或文件。如何实现它?

HTML code:

 <form id="file-up" action="upload_file.php" method="post" enctype="multipart/form-data" class="dropzone" id="my-awesome-dropzone">

 <div class="fallback">

 <input type="file" id="upload_file" name="upload_file[]"  multiple/> 
 <input type='hidden' id='uploadvalues' />

 </div>

 </form>

jquery

   <script type="text/javascript">

    Dropzone.options.myAwesomeDropzone = {
      maxFilesize: 20, // Size in MB
      addRemoveLinks: true,
        removedfile: function(file) { 
          var fileRef;
          return (fileRef = file.previewElement) != null ? 
                  fileRef.parentNode.removeChild(file.previewElement) : void 0;
        },

   success: function(file, response) {
              alert(response);
            },

   error: function(file, response) {
                  alert(response);
            }

 };




  </script>

用于上传的PHP服务器端代码

     <?php
      if(isset($_POST['submit_image'])){
     $ds          = DIRECTORY_SEPARATOR;  //1

     $storeFolder = 'uploads';   //2

     if (!empty($_FILES)) {

     $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

       }
     }
    ?>

1 个答案:

答案 0 :(得分:0)

您可以创建类似的delete.php文件。

</p>
include 'db.php';
$upload_dir = 'myuploads';
$targetPath = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . $upload_dir . DIRECTORY_SEPARATOR;
unlink($targetPath.$_GET['fid']);
$obj=new DB();
$sql = "DELETE FROM file_upload WHERE f_name='".$_GET['fid']."'";
$retval = mysqli_query($obj->connection(),$sql);
print_r("Successfully deleted.");
<p style="text-align: justify;">

从评论中更新:如果我理解正确,您希望X删除dropzone中的文件。

removedfile: function(file) {
    x = confirm('Do you want to delete?');
    if(!x)  return false;
}