Created
December 27, 2017 19:29
-
-
Save MrDavidChz/a6def5d7ca1f70211892968f515ca760 to your computer and use it in GitHub Desktop.
Laravel Dropzone - with submit button
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//add function to Controller | |
public function uploadFiles(Request $request){ | |
$tipo_factura = $request->input('tipo_factura'); | |
$file = $request->file('files'); | |
$fileName = $file->getClientOriginalName(); | |
$path = "uploads/facturas/"; | |
$expediente_id = $request->input('expediente_id'); | |
if ($file->move($path, $fileName)) { | |
echo "se movio correctamente el archivo"; | |
$upload=$path.$fileName; | |
$this->save_xml($upload,$expediente_id,$tipo_factura); | |
//create model | |
$Facturas = new Facturas; | |
$Facturas->id_expediente = $expediente_id; | |
$Facturas->tipo_factura = $tipo_factura; | |
$Facturas->xml = $upload; | |
if ($Facturas->save()) { | |
echo 'se inserto correctamente'; | |
} else { | |
echo 'ups hubo una falla'; | |
} | |
} else { | |
echo "error"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@extends('layout.master') | |
@section('head') | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.3.0/min/dropzone.min.css"> | |
@stop | |
@section('content') | |
<div class="col-md-12"> | |
<div class="panel panel-default"> | |
<div class="panel-heading">Informacion del expediente <a class="btn btn-default btn-xs pull-right" href="#" role="button"><span class="glyphicon glyphicon-arrow-left"></span> Atras</a></div> | |
<div class="panel-body"> | |
<div class="row"> | |
<div class="col-md-12"> | |
<button id="submit" class="btn btn-primary pull-right" ><span class="glyphicon glyphicon-plus"></span> Subir todas las Facturas</button> | |
<h4>Facturas</h4> | |
<div class="panel-body"> | |
{!! Form::open([ 'route' => [ 'facturas.uploadFiles' ], 'files' => true, 'class' => 'dropzone','id'=>"files"]) !!} | |
<input type="hidden" name="expediente_id" value='{{$expediente_id}}'> | |
<input type="hidden" name="tipo_factura" value='{{$tipo_factura}}'> | |
{!! Form::close() !!} | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
@endsection | |
@section('footer') | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.3.0/min/dropzone.min.js"></script> | |
@stop | |
@push('scripts') | |
$(document).ready(function () { | |
Dropzone.options.files = { | |
// Prevents Dropzone from uploading dropped files immediately | |
autoProcessQueue: false, | |
dictDefaultMessage: "Arrastre sus Archivos XML o de click AQUI para cargar sus archivos", | |
parallelUploads: 10, | |
paramName: "files", | |
maxFilesize: 100 ,// Tamaño máximo en MB | |
acceptedFiles: ".xml", | |
init: function() { | |
var submitButton = document.querySelector("#submit") | |
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. | |
}); | |
this.on("queuecomplete", function (file) { | |
alert("Todos los archivos se han cargo correctamente"); | |
}); | |
}, | |
success: function(file, response) { | |
console.log(response); | |
} | |
}; | |
}); | |
@endpush | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//add source to routes.php | |
Route::post('uploadFiles',array('as'=>'facturas.uploadFiles','uses'=>'FacturasController@uploadFiles')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment