In this tutorial, We will learn how to add a download link in dropzone js. We will help you to give an example of the dropzone add download link.



Follow some steps:



Step 1:

Create index.php file

<!DOCTYPE html>
<html>
<head>
  <title>PHP - Dropzone Add Download Button Example</title>
  <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <link href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.0.1/min/dropzone.min.css" rel="stylesheet">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.2.0/min/dropzone.min.js"></script>
</head>
<body>
   
<div class="container">
  <div class="row">
    <div class="col-md-12">
      <h2>PHP - Dropzone Add Download Button Example</h2>
      <form action="upload.php" enctype="multipart/form-data" class="dropzone" id="image-upload">
        <input type="hidden" name="request" value="add">
        <div>
          <h3>Upload Multiple Image By Click On Box</h3>
        </div>
      </form>
    </div>
  </div>
</div>
   
<script type="text/javascript">
  
    Dropzone.autoDiscover = false;
  
    var myDropzone = new Dropzone(".dropzone", { 
       maxFilesize: 10,
       acceptedFiles: ".jpeg,.jpg,.png,.gif",
       success: function (file, response) {
        if(response != 0){
           var anchorEl = document.createElement('a');
           anchorEl.setAttribute('href',response);
           anchorEl.setAttribute('target','_blank');
           anchorEl.innerHTML = "<br>Download File";
           file.previewTemplate.appendChild(anchorEl);
        }
       }
    });
   
</script>
  
</body> 

</html>



Step 2: 

Create upload.php file

<?php
  
$uploadDir = 'upload';
  
$tmpFile = $_FILES['file']['tmp_name'];
$filename = $uploadDir.'/'.$_FILES['file']['name'];
move_uploaded_file($tmpFile,$filename);
  
echo $filename;
  
?>


Step 3: 

Create upload folder for store images



Finally, You have to run your application..