Laravel And Dropzone - How To Get Files In Server Side
I'm trying to use dropzone in laravel project but I can't get the files in server side. My blade html code: {!! Form::open(['id' => 'create-intervention-form', 'url' => '/cre
Solution 1:
Add to your form open method 'files' => true
Solution 2:
You can try to get the files thought Request too in a loop:
Controller:
publicfunctionstore(Request $request)
{
$rules = array();
// do the validation ----------------------------------// validate against the inputs from our form$validator = Validator::make(Input::all(), $rules);
// check if the validator failed -----------------------if ($validator->fails())
{
// get the error messages from the validator$messages = $validator->messages();
return redirect()->back()->withErrors($validator)->withInput();
}
else
{
foreach( $request->file('file') as$file ){
$filename = $file->store('file');
#saves the file$array_images_names[] = $filename;
}
var_dump($files);
}
};
JavaScript (allowing to accept multiple files)
var post_url_images = $('#post_url_images').val();
Dropzone.options.frm_drop_images = {
paramName: "file", // The name that will be used to transfer the filemaxFilesize: 1024,
// The configuration we've talked about aboveurl: post_url_images,
autoProcessQueue: false,
uploadMultiple: true,
parallelUploads: 100,
maxFiles: 100,
// The setting up of the dropzoneinit: function() {
var myDropzone = this;
// First change the button to actually tell Dropzone to process the queue.this.element.querySelector("button[type=submit]").addEventListener("click", function(e) {
// Make sure that the form isn't actually being sent.
e.preventDefault();
e.stopPropagation();
myDropzone.processQueue();
});
// Listen to the sendingmultiple event. In this case, it's the sendingmultiple event instead// of the sending event because uploadMultiple is set to true.this.on("sendingmultiple", function() {
// Gets triggered when the form is actually being sent.// Hide the success button or the complete form.
});
this.on("successmultiple", function(files, response) {
// Gets triggered when the files have successfully been sent.// Redirect user or notify of success.
});
this.on("errormultiple", function(files, response) {
// Gets triggered when there was an error sending the files.// Maybe show form again, and notify user of error
});
}
};
Try to use your HTML form as below:
<divclass="dropzone dropzone-previews"id="frm_drop_images"class="dropzone"method="post"action="{{ url('/admin/products/upload/image') }}"></div><!-- hiddent field to set where to post the images --><inputtype="hidden"name="post_url_images"id="post_url_images"value="{{ url('/create-intervention') }}" ><divclass="btn-new-bottom"><ahref="#new-intervention">Criar Intervenção (Não precisa usar este botão)</a></div>
Post a Comment for "Laravel And Dropzone - How To Get Files In Server Side"