Problems downloading in CodeIgniter 3

1

In the view I created this link:

<td>
    <?php
        echo anchor("./anexos/cartao-confirmacao.pdf", 
            "<i class='glyphicon glyphicon-arrow-down'></i>",
            ['class' => 'btn btn-primary btn-block', 'name' => 'baixar']);
    ?>
</td>

From inside this folder anexos there is the file .pdf , but when I click the link, it goes to a page that says the following error:

  

404 Page Not Found The page you requested was not found.

link that function anchor creates: http://localhost/fideliza/anexos/cartao-confirmacao.pdf

I do not want it to go to a page and instead download the file that is in the anexos folder

    
asked by anonymous 25.10.2017 / 19:53

2 answers

1

If you are returning the header (error) 404 is because the link is broken, that is, it is not finding the file, look if the path is right.

If you do not want to be redirected to another page when you click the link, you have to add the download attribute in the link, following example:

<td><?php echo anchor("./anexos/cartao-confirmacao.pdf", "<i class='glyphicon glyphicon-arrow-down'></i>", ['class' => 'btn btn-primary btn-block', 'name' => 'baixar', 'download' => 'nome_da_imagem']); ?></td>
    
25.10.2017 / 20:02
0
<a href="<?php echo base_url(); ?>anexos/cartao-confirmacao.pdf" download<i class='glyphicon glyphicon-arrow-down'></i>Baixar</a>

Use this

    
21.05.2018 / 19:28