PHP : Upload multiple file using dropzone.js with drag and drop features

PHP : Upload multiple file using dropzone.js with drag and drop features

In this post we will give you information about PHP : Upload multiple file using dropzone.js with drag and drop features. Hear we will give you detail about PHP : Upload multiple file using dropzone.js with drag and drop featuresAnd how to use it also give you demo for it if it is necessary.

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.

Step 1 : Create File “index.php” to upload file

First we will create a file “index.php” with simple HTML form to upload file.

  1. <!DOCTYPEhtml>
  2. <htmllang="en">
  3. <head>
  4. <metacharset="utf-8">
  5. <metahttp-equiv="X-UA-Compatible"content="IE=edge">
  6. <metaname="viewport"content="width=device-width, initial-scale=1">
  7. <title>Laravel: upload multiple file using dropzone.js</title>
  8. <linkhref="//css/dropzone.css"rel="stylesheet">
  9. <scriptsrc="//js/dropzone.js"></script>
  10. </head>
  11. <body>
  12. <h3>PHP : Upload multiple file using dropzone.js with drag and drop features</h3>
  13. <formaction="upload.php"class="dropzone">
  14. </form>
  15. </body>
  16. </html>
<!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="//css/dropzone.css" rel="stylesheet">
    <script src="//js/dropzone.js"></script>
</head>
<body>

<h3>PHP : Upload multiple file using dropzone.js with drag and drop features</h3>
<form action="upload.php" >

</form>

</body>
</html>


Step 2: Create file “upload.php” to process the uploaded file

Now in this step, We will create a upload.php to process the uploaded files.

  1. <?php
  2. $targetDir='uploads/';
  3. if(!empty($_FILES)){
  4. $targetFile=$targetDir.time().'-'.$_FILES['file']['name'];
  5. move_uploaded_file($_FILES['file']['tmp_name'],$targetFile);
  6. }
  7. ?>
<?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

Show Demo

Hope this code and post will helped you for implement PHP : Upload multiple file using dropzone.js with drag and drop features. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  35  =  43

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US