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
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.
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.
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.
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); }); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With