Button to force Download without showing your way

Asked

Viewed 2,144 times

2

Hello,

I have a main html site meusite.com that can be found by the search engines' robots and made meusite.com/download.html with these parameters<meta name="robots" content="noindex, nofollow, nosnippet, noodp, noarchive, noimageindex"> not to be found in the search engines and where I want to create a download button for the files . PDF . DOC and . DOCX without the person seeing the file path <a href="http://meusite.com/download/arquivo.pdf">, without this file being indexed by the search engines and without the person being able to download it by typing for example meusite.com/download/file.pdf I found some information on the internet via php, but most linked to the need to create a login on the download page. The idea is to pass this link (meusite.com/download.html) to some people and that they can only download there.

  • I put the download files outside public_html to make it difficult to directly access them for example with https://meusite.com/download/arquivo.doc
  • I have how to make a download button without showing the direct link and if possible renaming the file ex: 759345798357934.pdf to file1.pdf and sdjfhksdjfksdjf.doc to file2.doc making it difficult to search for this file?
  • I have how to create a second button view PDF in the browser itself without also showing the real path and changing its name?

Thanks in advance for the help.

1 answer

1


You can make PHP pass the file to itself and change the header can make the download automatic:

pdf.php In the attribute filename= you set the download name for the file that is different from the original.

<?php
if(isset($_GET['id']) && !empty($_GET['id'])){
    // Exemplo de buscar o arquivo
        $file = "./contos_de_fadas/".$_GET['id'].".pdf";
    // Cabeçalho PDF
    $dl="inline";
    if(isset($_GET['download'])){$dl="attachment";}
    header("Content-type:application/pdf");
    header('Content-Transfer-Encoding: binary');
    header("Content-Disposition: ".$dl."; filename=nome_falso.pdf");
    header('Content-Length: ' . filesize($file));
    header('Accept-Ranges: bytes');
    @readfile($file);
}else{
    echo "Nenhuma ID selecionada";
}
?>

Example in HTML+JAVASCRIPT:

function pdfView(t){
document.location = "pdf.php?id="+t.name;
}
function pdfDownload(t){
document.location = "pdf.php?id="+t.name+"&download";
}
<input type="button" onclick="pdfView(this)" name="chapeusinho_vermelho" value="Chapéusinho Vermelho" />
<input type="button" onclick="pdfDownload(this)" name="chapeusinho_vermelho" value="Download" />
<br>
<input type="button" onclick="pdfView(this)" name="tres_porquinhos" value="Os Três Porquinhos" />
<input type="button" onclick="pdfDownload(this)" name="tres_porquinhos" value="Download" />
<br>

This way not only the links will be hidden, but the user’s download manager will also not have access to except by PHP.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.