Download button without showing your way

2

Hello,

I have a main mysite.com html site that can be found by search engine robots and I've done myite.com/download.html with these parameters <meta name="robots" content="noindex, nofollow, nosnippet, noodp, noarchive, noimageindex"> not to be found in search engines and where I want to create a download button for the .PDF files .DOC and .DOCX without the person seeing the path of the file <a href="http://meusite.com/download/arquivo.pdf"> , without that file can be indexed by the search engines and without the person being able to download by typing eg myite.com/download/film .pdf I found some information on the internet via php, but most coupled 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 they can only download it there.

  • I placed the download files outside of public_html to make it difficult to access them directly, for example with link
  • How do I 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?
  • How do I create a second PDF view button in the browser without also showing the actual path and changing its name?

Thanks for the help right away.

    
asked by anonymous 02.03.2018 / 20:37

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 filename = attribute 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>

In this way, not only will the links be hidden, but the user's download manager will also not have access other than by PHP.

    
03.03.2018 / 00:54