download / print file saved in postgresql database with php

0

I uploaded a file to the postgresql database with the OID column type. With the code below I can view / open the file in the browser, but I intend to download and / or print this same file on the printer with php. The files will be of any extension.

$query= pg_query($dbconn,"select * from tabela") or die(pg_last_error($dbconn));
$queryRow= pg_fetch_assoc($query);
$file = $queryRow['doc'];

pg_query($dbconn, "begin");
$handle = pg_lo_open($dbconn, $file, "r");
pg_lo_read_all($handle);
pg_query($dbconn, "commit");
    
asked by anonymous 26.04.2018 / 20:20

1 answer

0

Resolved as follows:

// consulta postgresql
$query = pg_query($dbconn,"select *, encode(lo_get(arquivo),'base64') as arquivo1 from tabela where id = 1") or die(pg_last_error($dbconn));
$queryRow = pg_fetch_assoc($query);

// link para download
<a download="arquivo.png" href="data:image/png;base64,<?php echo $queryRow['arquivo1'];?>">Download</a>
    
30.04.2018 / 16:27