Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
How to prevent dropZone to go over maxFile after reload the page

I am using the maxFile parameter for DropZone to allow in maximum one picture in the dropzone. It's working as long we do not reload the page. During the reload we read the files from the server an add the file into the dropzone. If there then one picture in the dropzone, then we can add another picture. See the code below! Where is my mistake?

Dropzone.autoDiscover = false;


$("#Titelbild").dropzone({
  maxFiles: 1,
  maxFilesize: 2, // Filesize 2 MByte  
  addRemoveLinks: true,
  acceptedFiles: ".jpeg,.jpg,.png,.gif,.jfif",
  
removedfile: function(file) {
       var fileName = file.name; 
         
       $.ajax({
         type: 'post',
         url: 'Delete_picture.php',
         data: {name: fileName, request: 'delete'},
         sucess: function(data){
            console.log('success: ' + data);
            // alert(data);
         }
        });

        var _ref;
        return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0;
  },  

  init: function() { 
    myDropzone1 = this;
  
    $.ajax({
      url: 'Fetch_picture.php',
      type: 'post',
      data: {request: 'fetch'},
      dataType: 'json',      
      success: function(response){
        var filecounter = 0;

        $.each(response, function(key,value) {
          var mockFile = { name: value.name, size: value.size};
          myDropzone1.emit("addedfile", mockFile);
          myDropzone1.emit("thumbnail", mockFile, value.path);
          myDropzone1.emit("complete", mockFile);

          };

        });

    }
   
    });
    
  }
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Add this

myDropzone1.files.push(mockFile);

after your line

myDropzone1.emit("complete", mockFile);

This did the trick for me

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!