I am running into the issue where the form input fields are not passing data along with the files when I try to integrate dropzone into my form. I need it to pass the additional fields as it contains info for the file name for the files. Here is what I have, if someone could please tell me what I am doing wrong. I have removed some folder/file names for security, I italiced those
Form Page:
<form action="upload_photos.php" method="post" enctype="multipart/form-data">
<div class="form_quartercontent">
<select name="fp_id" id="fp_id">
<option value="*some option*" >*Option Label*</option>
</select>
</div>
<div class="form_quartercontent">
<input name="order_id" type="hidden" id="order_id" value="the order id #" />
</div>
<div class="clear"></div>
<div class="dropzone" id="myDropzone"></div>
<div class="form_quartercontent"><input name="submit-all" type="submit" class="form-submit-button" id="submit-all" value="Upload Photo" /></div></form>
<script>Dropzone.options.myDropzone= {
url: 'upload_photos.php',
autoProcessQueue: false,
uploadMultiple: true,
parallelUploads: 100,
maxFiles: 100,
maxFilesize: 3,
acceptedFiles: 'image/*',
addRemoveLinks: true,
init: function() {
var dzClosure = this; // Makes sure that 'this' is understood inside the functions below.
// for Dropzone to process the queue (instead of default form behavior):
document.getElementById("submit-all").addEventListener("click", function(e) {
// Make sure that the form isn't actually being sent.
e.preventDefault();
e.stopPropagation();
dzClosure.processQueue();
});
//send all the form data along with the files:
this.on("sending", function(file, xhr, formData) {
//formData.append('task_name', jQuery('#task_name').val());
$("form").find("input").each(function(){
formData.append($(this).attr("name"), $(this).val());
});
});
}
}
</script>
**
Upload PHP:**
$order_photo = $_POST['order_id'];
$photo_fp = $_POST['fp_id'];
if(!empty($_FILES)){
// Include the database configuration file
require("includes/*databaseconnection.php*");
if(!($p_update = mysqli_query($link,"INSERT INTO *table* SET order_id='$order_photo',fp_id='$photo_fp'"))){
printf("%s", sprintf("internal error %d:%sn", mysqli_errno(), mysqli_error()));
exit();
}
$photo_id = mysqli_insert_id($link);
$extension = strrchr($_FILES['file']['name'],'.');
$extension = strtolower($extension);
$save_path = '*pathtofolder*/'. $order_photo .'/*storingfolder*/';
if(!is_dir($save_path)) mkdir($save_path);
$filename = $save_path . $order_photo ."_". $photo_fp."_". $photo_id . $extension;
move_uploaded_file($_FILES['file']['tmp_name'],$filename);
}
2
Answers
This is my working solution:
Form Page:
upload_photos.php:
deleteFiles.php:
my database structure:
You could have also used the
formData.append("variableName", "valueOfVariable")
and in your*.php
file just read the$_POST['variableName']
. This way you can get rid of$("form").find("input")
functions.