-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.

BobRodes
  • 5,990
  • 2
  • 24
  • 26
  • 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? – M. Eriksson Sep 06 '18 at 21:15
  • You want to implement a small "router script" in php which is requested by your anchor (`anchor`). That script internally fetches the file from the FTP server (php has FTP classes) and forwards it to the requesting client. – arkascha Sep 06 '18 at 21:20
  • https://stackoverflow.com/questions/7263923/how-to-force-file-download-with-php – Chris Sep 06 '18 at 21:26

1 Answers1

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

Mason
  • 789
  • 1
  • 7
  • 16