Hide download link [duplicate]

0

I have a difficulty, I made a system that frees file download for each specific user, this check is done by the user code logged in and month and year filters that the user fills, so necessarily the person has to be logged in to but I do not want to use this link to download the file again and this is what I did not want, I would like this link to be hidden, is there any way to do that?

<?php
$pasta = '/arquivos';
$arquivos = "$user->cod_func".'  '.utf8_decode($_POST['select_mes']).' de '.$_POST['select_ano'].'.pdf';
$filename = 'arquivos/'.$arquivos;

if (file_exists($filename)) {
?>  
Download do Arquivo: <a href="?action=download&file=<?php echo base64_encode("$pasta/$arquivos"); ?>"><?php echo $_POST['select_mes'].' '.$_POST['select_ano']; ?></a>
<br>
Vizualizar: <a href="?action=embed&file=<?php echo base64_encode("$pasta/$arquivos"); ?>"><?php echo $_POST['select_mes'].' '.$_POST['select_ano']; ?></a>
<br>

<?php
} else {
echo "Não existe holerith no mês selecionado";
}
?>
    
asked by anonymous 10.11.2016 / 19:53

1 answer

0

Two alternatives:

The first and easiest is to enter this page where you have the link to download, you save in the session the file that will be downloaded. The link does not need this parameter anymore, it can only be / download. In this / download, for example, you check if there is any file in the session and if there is, you send that file that you do not even do in the current link, but this prevents it from opening two pages like that.

The other alternative is to create a table with the randomly generated one key (primary key), the user's oid, and the file to download. When entering this page you create this record and in the url, instead of passing the parameter file, you can pass the key and there on the other page fetch the file by key in the database and return the file to download.

    
11.11.2016 / 14:57