The problem is everytime I hit the upload button to saved all images in database it will saved one by one. Ex: I upload two images on dropzone and submit it..the data will be saved in database is two column which is wrong what I want to display is only one column with multiple images. Hoping you can help me with these. Thanks ahead!
Dropzone js code:
Dropzone.options.myDropzone = {
// Prevents Dropzone from uploading dropped files immediately
autoProcessQueue: false,
init: function() {
var submitButton = document.querySelector("#submit-all")
myDropzone = this; // closure
submitButton.addEventListener("click", function() {
myDropzone.processQueue(); // Tell Dropzone to process all queued files.
});
// You might want to show the submit button only when
// files are dropped here:
this.on("addedfile", function() {
// Show submit button here and/or inform user to click it.
});
}
};
HTML:
<button id="submit-all">Submit all files</button>
<form action="upload.php" class="dropzone" id="my-dropzone"></form>
My php code:
<?php
if(!empty($_FILES)){
$targetDir = "../drop/../images/";
$fileName = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
$img = $_FILES['file']['name'];
$img_name = $id . "_" . uniqid() . "_" . ($_POST['default_pic'] == $img ? "1" : "0") . "." . $fileName;
$targetFile = $targetDir.basename($img_name);
if (move_uploaded_file($_FILES['file']['tmp_name'],$targetFile)){
$new_data = array("cover" => ($_POST['default_pic'] == $img ? "1" : "0"), "img" => $img_name);
$new_array[] = $new_data;
$data_serialize = serialize($new_array);
//insert file information into db table
$mysqli->query("INSERT INTO files (file_name, uploaded) VALUES('".$data_serialize."','".date("Y-m-d H:i:s")."')");
//$new_id = $mysqli->insert_id;
}
}
?>
$_FILESis structured, I'll update the answer.