I'm working on an Application in the Laravel 5 framework which requires multiple images to be uploaded. For this, I have a form which with a file input (I researched and came across dropzone.js so I'm using this like this)
<form method="POST" enctype="multipart/form-data">
<div class="form-group">
<label for="inputAccName">Name:</label>
<input type="text" name="inputAccName" class="form-control" id="inputAccName" required="true" value="{{ Auth::user()->name }}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</div>
<div class="dropzone" id="dropzoneFileUpload">
</div>
<script type="text/javascript">
var baseUrl = "{{ url('/') }}";
var token = "{{ Session::getToken() }}";
Dropzone.autoDiscover = false;
var myDropzone = new Dropzone("div#dropzoneFileUpload", {
url: baseUrl+"/user/uploadFiles",
params: {
_token: token
}
});
Dropzone.options.myAwesomeDropzone = {
paramName: "file", // The name that will be used to transfer the file
maxFilesize: 2, // MB
addRemoveLinks: true,
accept: function(file, done) {
},
};
</script>
<input class="btn btn-success btn-lg" type="submit" name="formPassword" value="Save Changes">
</form>
So the user will input the name and upload up to 4 pictures (minimum 1 required).
I have a POST route which calls a function called "UpdateUserX" this function updates the user name in the database when the form is submitted.
In a separate function I have added the following code for the files upload:
public function uploadFiles()
{
$destinationPath = 'uploads'; // upload path
$extension = Input::file('file')->getClientOriginalExtension(); // getting file extension
$fileName = rand(11111, 99999) . '.' . $extension; // renaming image
$upload_success = Input::file('file')->move($destinationPath, $fileName); // uploading file to given path
if ($upload_success) {
return Response::json('success', 200);
} else {
return Response::json('error', 400);
}
}
This function is called by dropzone when images are uploaded. What I want to do from here is parse the details of uploaded images to the UpdateUserX function so i can store the details of the images in the database. Any advice in the right direction would be appreciated.
uploadFilesmethod, so you can identify them later.