Cannot upload multiple files using dropzone

I use the dropzone.js library, but it does not work.

In the upload script, I count the files to see if it works:

$file_count = count($_FILES['file']['name']);
echo $file_count;

But it only prints 1 all the time (I tried to load 2 +).

HTML:

<form id="propForm" class="" name="" action="upload.php" method="POST" enctype="multipart/form-data">
    <div class="option img">
        <h4>Imagenes (m&#225;ximo 6):</h4>
        <div id="dropzone" class="dropzone">
        // hidden input is appended here
        </div>
    </div>
    // more inputs
    <input value="Subir" type="submit" name="submitIT">
</form>

Dropzone Options:

$('div#dropzone').dropzone({
    url: 'upload.php',
    paramName: "file[]", // The array is initialized here but it not working
    acceptedFiles: 'image/*',
    addRemoveLinks: true,
    parallelUploads: 6,
    maxFilesize: 6,
    maxFiles: 6,
    autoDiscover: false,
    autoProcessQueue: false,
    uploadMultiple: true,
    hiddenInputContainer: '#dropzone',

    init: function () {
        thisDropzone = this;
        thisDropzone.on("maxfilesexceeded", function(file) { thisDropzone.removeFile(file); });
        $("input[type=submit]").click(function(e){ 
            e.preventDefault();
            thisDropzone.processQueue();
        });
        this.on("successmultiple", function(files, response) {
            alert('works');
            $("form#propForm").submit();
        });
    }
});

Output Upload.php:

1  // output for echo $file_count;
Notice: Uninitialized string offset: 0 // $filen = $_FILES['file']['name'][$i]; (inside a for)

EDIT: it worked, only the files loaded first than the form, so I got 1 and a notification.

+4
source share
1 answer

, ( ), , , . - , jquery plugin: , ( , jquery), .

, , , , script :

if ($_FILES['file']['error'] == 0) {
// move_uploaded_file (single file)
// or a for($i=0; $i < $file_count; $i++) (multiple files)
}

if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
//filter the data and store it in db
}
0

Source: https://habr.com/ru/post/1615778/


All Articles