Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dropzone upload only one file

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..

here is my 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> 

i changed dropzone.js

maxFiles: 1 

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

like image 911
user3064914 Avatar asked Feb 25 '14 05:02

user3064914


People also ask

What is dropzone file upload?

Dropzone is a simple JavaScript library that helps you add file drag and drop functionality to your web forms. It is one of the most popular drag and drop library on the web and is used by millions of people.

What is processQueue dropzone?

processQueue() which checks how many files are currently uploading, and if it's less than options. parallelUploads , . processFile(file) is called. If you set autoProcessQueue to false , then . processQueue() is never called implicitly.

How do I create a dropzone file?

Set Dropzone autoDiscover to false and initialize dropzone on class="dropzone" . Send AJAX POST request from init function to get all the files list. On successfully callback loop on the response and assign { name: value.name, size: value.


1 Answers

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);       }); }    
like image 95
NeoNe Avatar answered Sep 20 '22 23:09

NeoNe