Hello Devs,

In this tutorial, we are going to learn how to drag and drop file upload using dropzone js and php.

Follow this step by step guide given below:




Step 1 : 


Create index.php File 

<!DOCTYPE html>
<html>
<head>
    <title>Drag and Drop File Upload using Dropzone JS and PHP - Rathorji.in</title>
    <script src="http://demo.itsolutionstuff.com/plugin/jquery.js"></script>
    <link rel="stylesheet" href="http://demo.itsolutionstuff.com/plugin/bootstrap-3.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>Drag and Drop File Upload using Dropzone JS and PHP - Rathorji.in</h2>
            <form action="upload.php" enctype="multipart/form-data" class="dropzone" id="image-upload">
                <div>
                    <h3>Drag and Drop File</h3>
                </div>
            </form>
        </div>
    </div>
</div>

<script type="text/javascript">
    Dropzone.options.imageUpload = {
        maxFilesize:1,
        acceptedFiles: ".jpeg,.jpg,.png,.gif"
    };
</script>

</body>
</html>



Step 2 :


 Create upload.php File

<?php

$uploadDir = 'uploads';

if (!empty($_FILES)) {
 $tmpFile = $_FILES['file']['tmp_name'];
 $filename = $uploadDir.'/'.time().'-'. $_FILES['file']['name'];
 move_uploaded_file($tmpFile,$filename);
}

?>



Step 3 : 


Create upload folder Run this command:

php -S localhost:8000

Open this URL:

http://localhost:8000


I hope this example helps you.