There is the possibility of downloading multiple files in a single link. I have tried in many ways and I have not obtained results if someone can give a force.
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;
}
}
There are 03 files I'm only able to download one. In the query I am putting the GROUP BY
so that the return of the bank is not very extensive