In this PHP Tutorial, I will tell you how to upload multiple files using dropzone.js plugin with drag and drop features.
It's very easy to upload files to the server with PHP script.
You will need a HTML form with PHP script to allow user to upload files to the server.
In PHP, There is a global PHP variable $_FILES that keeps all the information related to uploaded files.
Basically files are stored into a temporary directory and then you use PHP script to move files to target destination.
With dropzone.js, You can see the nice progress bar while uploading files to server.
You need to have a simple form element with the class "dropzone" to use dropzone features.
For this example :
- Create a folder "uploads" to save all uploaded files.
- Create a file "index.php" for form element.
- Create a file "upload.php" to handle backend file upload process.
First we will create a file "index.php" with simple HTML form to upload file.
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <title>Laravel: upload multiple file using dropzone.js</title>
- <link href="http://demo.expertphp.in/css/dropzone.css" rel="stylesheet">
- <script src="http://demo.expertphp.in/js/dropzone.js"></script>
- </head>
- <body>
- <h3>PHP : Upload multiple file using dropzone.js with drag and drop features</h3>
- <form action="upload.php" class="dropzone">
- </form>
- </body>
- </html>
Now in this step, We will create a upload.php to process the uploaded files.
- <?php
- $targetDir = 'uploads/';
- if (!empty($_FILES)) {
- $targetFile = $targetDir.time().'-'. $_FILES['file']['name'];
- move_uploaded_file($_FILES['file']['tmp_name'],$targetFile);
- }
- ?>
Laravel 5 - Multiple Images Uploading with drag and drop using dropzone.js example