4
I’m setting up a job where I need to release the file download on pdf, however this file is saved in the database it is in format base64.
My idea is to do when the comrade clicks on the line he does the download, of the archive.
I tried to look for something but I didn’t find anything that clears my doubt.
My table is getting like this:
echo '<tr>'
. '<td><a class="ajax-link" href="ajax/gerapdf.php?id=' . $registro->DAT_PUBLIC_DOWNL . '">' . $registro->DAT_PUBLIC_DOWNL . '</a></td>'
. '<td>' . $registro->TXT_TITUL_DOWNL . '</td>'
. '<td>' . $registro->TXT_EXTEN_ARQUI . '</td>'
. '</tr>';
gerapdf.php
<?php
header("Content-type:application/pdf");
header("Content-Disposition:attachment;filename='arquivo.pdf'");
include '../includes/suc_validacao.php';
include '../includes/conexao.php';
$id = !empty($_GET['id']) ? $_GET['id'] : 0;
$conexao = new ConexaoDatabase();
$sql = "SELECT BLO_PDFXX_ARQUI FROM DB_EGLISE.tbl_DOWNLOADS WHERE COD_IDENT_IGREJ = :igj and DAT_PUBLIC_DOWNL = :data";
$sqlVars = array();
$sqlVars[':igj'] = $suc->getCOD_IDENT_IGREJ();
$sqlVars[':data'] = $id;
$registros = $conexao->fetch($sql, $sqlVars);
echo base64_decode($registros->BLO_PDFXX_ARQUI);
The exit was this:

Maybe I need to do the
base64_decode()and then just format the upload header– rray
Directly there is no way to do it, as in the example I added @rray
– Renan Rodrigues
A suggestion is instead to imprint the pdf, put the link to a php (new) file that makes the query at the base takes the content and formats the header to pdf.
– rray
Of curiosity, what makes someone save something in Base64 in DB? I see a lot of people doing this, I wanted to understand where this strange idea comes from. Zero benefit, and waste of space.
– Bacco
It would only make sense to use Base64 if it was to send via a text protocol... Accessing via JSON or XML is practical like this.
– Rodrigo Guiotti
The idea is to save in a database, as it would with XML ?
– Renan Rodrigues
The file that sends the PDF is in the folder
ajax/but make download via AJAX is complicated and I do not recommend, a direct link to download page will open the save file window and the current page remains loaded. Saving the file on base 64 increases the size by approximately 33%, according to Wikipedia, you can use columns Blob in the database, avoiding the need for decoding.– Pedro Sanção