2
There is the possibility to download multiple files in a single link. I have tried many ways and I have not achieved anything if someone can give a strength.
In the image the termosPedidoId
(78)
<?php
use App\Controllers\DB\Conn;
use App\controllers\Controller\Read;
use App\Controllers\Controller\Util;
$PDO = new Conn;
$Read = new Read;
$Util = new Util;
$result = $PDO->getConn()->prepare("SELECT * FROM tb_pedido_termos GROUP BY termosPedidoId");
$result->execute();
$dados = $result->fetchAll(PDO::FETCH_ASSOC);
foreach ($dados as $retorno){
?>
<table>
<tr>
<td><?php echo $retorno['termosPedidoId'] ?></td>
<td>
<a href="models/downloadUpload.php?id=<?php echo $retorno['termosPedidoId'] ?>">Download</a>
</td>
</tr>
</table>
<?php
}
// Arquivo que faz o download
<?php
require '../../vendor/autoload.php';
use App\Controllers\DB\Conn;
$PDO = new Conn;
$pasta = '../uploadTermos/';
$result = $PDO->getConn()->prepare("SELECT * FROM tb_pedido_termos WHERE termosPedidoId=".$_GET['id']."");
$result->execute();
foreach ($result as $res){
if(isset($_GET['id']) && file_exists("{$pasta}/".$res['termosPedidoName'])){
$file = $res['termosPedidoName'];
$type = filetype("{$pasta}/{$file}");
header("Content-Description: File Transfer");
header("Content-Type:{$type}");
header("Content-Disposition: attachment; filename=$file");
readfile("{$pasta}/{$file}");
$handler = fopen("{$pasta}/{$file}");
if ($handler) {
while (!feof($handler)) {
$buffer = fgets($handler, 4096);
echo $buffer;
}
fclose($handler);
}
exit;
}
}
has 03 files I am able to download only one. In query I’m putting the GROUP BY
so that the return of the bank is not too extensive