Problems with download in Codeigniter 3

Asked

Viewed 76 times

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 that folder anexos there is the file .pdf, but when I click on 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 to Function anchor calf: http://localhost/fideliza/anexos/cartao-confirmacao.pdf

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

2 answers

1

If you are returning the header (error) 404 is because the link is broken, IE, he is not finding the file, look if the way is right.

If you don’t want to be redirected to another page when clicking on the link, you have to add the attribute download in the link, below is an 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>
  • yes... now it is downloading with this tag, but it fails to download, as if the file did not exist, but it exists..

  • That’s what I said, your link is not pointing to the file correctly. The link is broken. Which is the path where the images are ?

  • http://localhost/fideliza/attachments/card-confirmation.pdf... the folder calls attachments and is not an image is a pdf file

  • On the link, instead of shortening the path, put the literal path and see if it works, put there href="localhost/fideliza/anexos/cartao-confirmacao.pdf"

  • doesn’t work yet... tried this: base_url("anexos/cartao-confirmacao.pdf") and it wasn’t either

  • Inspect the link you created and look where the href= There’s some mistake there.

  • I inspected: <a href="http://localhost/fideliza/anexos/cartao-confirmacao.pdf" class="btn btn-primary btn-block" name="download" download="download"><i class="glyphicon glyphicon-arrow-down"></i></a>... is right the way... inside the project folder fideliza has a folder called anexos.. is correct.. and the file is there

Show 2 more comments

0

<a href="<?php echo base_url(); ?>anexos/cartao-confirmacao.pdf" download<i class='glyphicon glyphicon-arrow-down'></i>Baixar</a>

Use this

Browser other questions tagged

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