-2

I´ve developed a web page and all good but I have a little question. I need that when I click on the name, this downloads the file. This file is located in a server FTP. How do I do this?

My php version is "4.7.0"

The code that I used is this:

<td>
    <a href="descarga.php?id=<?php echo $misdatos["record"];?>"?> 
    <?php echo $misdatos["record"]; ?></a>
</td"

Thank you for the help.

3
  • 4
    "My php version is "4.7.0"" - That's your first problem. Btw, from what I recall, 5.0 came after 4.4, so AFAIK, there weren't even a version called 4.7? Commented Sep 6, 2018 at 21:15
  • You want to implement a small "router script" in php which is requested by your anchor (<a href="...">anchor</a>). That script internally fetches the file from the FTP server (php has FTP classes) and forwards it to the requesting client. Commented Sep 6, 2018 at 21:20
  • stackoverflow.com/questions/7263923/… Commented Sep 6, 2018 at 21:26

1 Answer 1

0

You can use the download attribute:

<td>
    <a href="descarga.php?id=<?php echo $misdatos["record"];?>" download>
    <?php echo $misdatos["record"]; ?>
    </a>
</td>

this way, instead of opening the file in the browser, it will force the browser to download the resource.

you can check browser compatibility for download attribute here

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.