0
I created a directory within /public called /uploads/pdf. In this directory I keep PDF files from which I need to download. I created an AJAX request for this that calls an application controller for this, however, via AJAX does not work.
If I make the call it usually works.
Look at the code:
Pdfclass.php //Class I created globally registered
public static function createPDF($view){
define('BUDGETS_DIR', public_path('uploads/pdf'));
if (!is_dir(BUDGETS_DIR)){
mkdir(BUDGETS_DIR, 0755, true);
}
$outputName = str_random(10);
$pdfPath = BUDGETS_DIR.'/'.$outputName.'.pdf';
File::put($pdfPath, PDF::load($view, 'A4', 'portrait')->output());
}
As you can see, he already has the call to download the file.
In the controller I call this method to create the report and return.
Reservacontroller.php
PDFClass::createPDF(HTMLRelatorio::confirmacaoReserva($fileServico,$motorista));
That creates the PDF file, saves it in the specified directory, but... Does not open the download window because the call is by AJAX...
The call in the view: reserved.blade.php
$(this).on('click','#imprimirConfirmacao',function(){
var idFile = $('#id_file').val();
var idServ = $('#id_servico').val();
$.ajax({
url: '/reserva/imprimir',
type: 'POST',
dataType: 'html',
data: {idFile: idFile,idServ:idServ},
success: function(data){
console.log(data);
}
});
You could help me with that. If someone can give me a way to download the file via ajax or a way to access the absolute path to create a link by Laravel I appreciate, because if I make the call through the direct browser also returns error:
Look at:
http://meusite.com/uploads/pdf/arquivo.pdf OR http://meusite.com/public/uploads/pdf/arquivo.pdf
Returns error:
Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
This request is created because the report is created on time...
– Ewerton Melo