Try
dd($request->files(), $request->all())
to see/check if anything was sent.
Also look into your Debugbar/Console to see if there is an error
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
i'm trying to upload multiple files with Dropzone in one form along with some other data. When i dd the files after submit i always get null. Does anyone know how to deal with that?
<script>
$("div#dz").dropzone({ url: "{{ url('/store-item')}}",
acceptedFiles: '.jpg, .jpeg, .png',
maxFileSize: 1,
autoDiscover: false,
autoProcessQueue: false,
paramName: "file",
sendingmultiple: function(file, xhr, formData) {
formData.append("_token", "{{{ csrf_token() }}}");
},
completemultiple: function() {
alert('complete');
},
init: function() {
var submitButton = document.querySelector("#item-submit-button")
myDropzone = this;
submitButton.addEventListener("click", function() {
myDropzone.processQueue();
});
}
});
</script>
public function storeItem(Request $request)
{
// Validate and Store Photos //
$file = $request->file('file');
dd($file);
}
Hi,
after 1 Month of tryouts, switching to other upload plugins etc. i got it. If anyone is interessted of getting dropzone to work in a normal form here is my code. if you see something that can be improved please let me know.
<script>
// Disable AutoDiscover
Dropzone.autoDiscover = false;
// Set Dropzone Options
Dropzone.options.myAwesomeDropzone = {
autoProcessQueue: false,
uploadMultiple: true,
parallelUploads: 20,
maxFiles: 20,
addRemoveLinks: true,
acceptedFiles: ".jpg, .jpeg, .png",
maxFilesize: 1,
dictDefaultMessage: "Drop your files here!",
}
// Initialize Dropzone
var myDropzone = new Dropzone("#my-awesome-dropzone", {url: "/store-item"});
// Initialize Submit Button
var submitButton = document.querySelector("#submit");
// Submit Button Event on click
submitButton.addEventListener("click", function(e) {
e.preventDefault();
// Serialize Form
var form = $('#item-form').serialize();
$.ajax({
type: 'post',
// First, validate form
url: '/validate-item',
data: form,
success: function(){
// if dropzone has files processqueue and submit formdata with dropzone
if (myDropzone.getQueuedFiles().length > 0) {
myDropzone.processQueue();
} else {
// if dropzone has no files store item without images
$.ajax({
type: 'post',
url: '/store-item',
data:form,
success: function(){
window.location="{{URL::to('/items')}}";
}
});
}
},
error: function(data){
// on validate error show errors (using sweet alert)
var result = $.parseJSON(data.responseText);
var arr = [];
$.each(result, function(key, value) {
arr += value + "\n";
});
swal({
title: "Error!",
text: arr,
type: "error",
confirmButtonText: "Ok"
});
}
});
});
// on sending via dropzone append token and form values (using serializeObject jquery Plugin)
myDropzone.on("sendingmultiple", function(file, xhr, formData) {
formData.append('_token', '{{ csrf_token() }}');
var formValues = $('#item-form').serializeObject()
$.each(formValues, function(key, value){
formData.append(key, value);
});
});
// on success redirect
myDropzone.on("successmultiple", function(){
window.location="{{URL::to('/items')}}";
});
// on error show errors
myDropzone.on("errormultiple", function(file, errorMessage, xhr){
var arr = [];
$.each(errorMessage, function(key, value) {
arr += value + "\n";
});
swal({
title: "Error!",
text: arr,
type: "error",
confirmButtonText: "Ok"
});
});
</script>
Please or to participate in this conversation.