dropzone只上传一个文件 [英] dropzone upload only one file

查看:973
本文介绍了dropzone只上传一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用dropzone.js作为拖放文件上传解决方案。我只想上传一个文件,如果我上传第二个文件,第一个应该删除,第二个应该上传。
任何想法怎么做..

I am using dropzone.js for my drag-drop file upload solution. I want to upload only one file,if i upload second file the first one should be remove and second one should be uploaded. any idea how to do it..

这里是我的html

<form class="dropzone dz-clickable" action="upload.php" enctype='multipart/form-data'>
  <i class="fa fa-cloud-upload element"></i>
  <div style="color:gray;">Drag and drop or click to upload image</div>
  <input type="hidden" name="filenameEmail" class="filenameEmail" value="">
  <input type="hidden" name="side" value="front">
</form>

我更改了dropzone.js

i changed dropzone.js

maxFiles: 1

它只允许上传一个文件,但我不能删除以前上传的文件。请帮我out.thanks提前

it allow to upload only one file but i cant remove the previously uploaded file.please help me out.thanks in advance

推荐答案

maxFiles:1 是用来告诉dropzone应该只有一个文件。如果文件超过1个,将调用 maxfilesexceeded 功能,将超出文件作为第一个参数。

maxFiles: 1 is used to tell dropzone that there should be only one file. When there is more than 1 file the function maxfilesexceeded will be called, with the exceeding file as the first parameter.

这是一个删除第一个文件预览并添加新文件的简单函数:)

here is a simple function to delete preview of first file and add the new one :)

maxFiles:1,
init: function() {
      this.on("maxfilesexceeded", function(file) {
            this.removeAllFiles();
            this.addFile(file);
      });
}   

这篇关于dropzone只上传一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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