Dropzone.js not loading

I installed simple dropzone.js by following the guide on the Dropzon StarTutorial website . It shows dropzone correctly, and when I drop files, it will be displayed, but when I try to click the "Download" button, nothing happens. I am using this HTML code:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <link href="css/style.css" type="text/css" rel="stylesheet"/>
    <script src="js/dropzone.js"></script>
</head>
<body>
    <div id="main">
        <form action="upload.php" class="dropzone" id="zone"></form>
    </div>
</body>

And this PHP code:

<?php
$ds          = DIRECTORY_SEPARATOR;
$storeFolder = 'uploads';

if (!empty($_FILES)) {
    $tempFile = $_FILES['file']['tmp_name'];
    $targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;
    $targetFile =  $targetPath. $_FILES['file']['name'];
    move_uploaded_file($tempFile,$targetFile);
}
?>
+1
source share
3 answers

I had the same problem. This is due to indexing. Dropzone uploads multiple files at once. So the file name is in the array. Read the file using the key with foreach or forloop. I used this in CodeIgniter:

foreach ($_FILES["file"]["error"] as $key => $error)  {
    if ( $error == UPLOAD_ERR_OK ) {                
        $tempFile = $_FILES['file']['tmp_name'][$key];

        $name = $_FILES["file"]["name"][$key];
        $file_extension = end((explode(".", $name))); # extra () to prevent notice

        $targetPath = FCPATH . $storeFolder . $ds;  //4

        $file_new_name = uniqid(). '.'. $file_extension;

        $targetFile =  $targetPath. $file_new_name  ;  //5

        move_uploaded_file($tempFile,$targetFile); //6    
    }
} 
+2
source
  • JS?
  • PHP-? "uploads" ?
0

Try adding a submit button, method, and enctype to your form.

<form action="upload.php" class="dropzone" id="zone" method="post" enctype="multipart/form-data"> <input type="submit" name="submit" id="submit" /><!-- Submit button --> </form>

In your dropzonejs form, only those files or files that you want to upload are displayed, but dropzonejs does not upload any of your files to your server, you will need to send the files to your server using javascript on php or server.

I hope this will be helpful to you.

0
source

All Articles